F3031 Object Oriented Programming: Introduction To OOP Classes and Objects Exception Handling
F3031 Object Oriented Programming: Introduction To OOP Classes and Objects Exception Handling
1.0 ●
Introduction To OOP
2.0 ●
Classes And Objects
4.0 ●
Exception handling
© 2009 | PN NORHASLIZA BT MUHAMAD NOR
2
1.0INTRODUCTION TO
OBJECT – ORIENTED
PROGRAMMING (OOP)
LEARNING OUTCOMES
1 Define OOP
●
2 History Of OOP
●
Define OOP
• Programming paradigm that uses “objects" – data structures consisting of datafields
and methods – and their interactions to design applications and computer programs.
• A type of programming where the programmer can define data types and types of
operations, which will be performed on the data structure.
Example:
Data data types
Data Structure Student No. Integer
Mark float
Types of operation:
Student No. :
Sort student list based on Student No.
Mark :
Calculate mark.
• The programmer can create relationship between one object with another object such
as an object inherits characteristics from another object
History Of OOP
• ASSGMNT 1
Terminologies Of OOP
1. Object
Object is the term used to explain many things.
Example: student, chair and circle.
An Object consists of data and method
Properties of an object are called data. In the real world, characteristics of an object can be
divided into two types:
Data that can be seen such as a human with two hands.
Data that cannot be seen such as a human with a name.
Method is a set of function that manipulates data, such as method DetermineStatus() can
determine exam result for object student.
Objek : Pelajar
Data : nama, alamat, nokadpengenalan, sid,
markah, status
Method: MenentukanStatus()
Attributes and methods of a class can be used by each object from that class.
Class Student
Name, Student ID, Address,
IC No
Calculate_result()
Determine_grade()
Print_result()
Figure above Explains the concept of encapsulation in OOP for class Student
Based from the example given, data and methods are combined in one class. If the college management wants to
get the status whether a student “pass” or “fail”, they only have to know the status without knowing how to
determine or calculate the grade. So, this is a way of implementing encapsulation where the code in the program
is hidden thus to prevent from being modified.
Sifat/(Attribute)
Pengabstrakan
Nama, ID pelajar,
Alamat, No KP
Kelakuan/ (Behaviors)
Kira_markah (),
Tentu_gred (),
Cetak_keputusan ()
Class D Class E
Class C
Contoh 1:
Mesej: Keluarkan wang anda dari bank:
Objek Tindakan
Pelajar 1 : Menggunakan mesin ATM yang disediakan oleh pihak
bank di mana akaun dibuka
Setiap fungsi ditugaskan untuk satu tugas Ia boleh dilakukan melalui teknik pewarisan.
yang spesifik. Kita mesti menerima Teknik ini membolehkan objek untuk mewarisi
fungsi itu sebagaimana ia ditulis. ciri-ciri (fungsi dan data) objek lain.
Untuk mengubahsuainya, kod itu
haruslah disalin semula dan diubah untuk Contoh:
memenuhi keperluan. Kita menggunakan radio kegunaan rumah
Contoh: yang telah dicipta untuk digunakan pada
Kita telah merekacipta satu radio untuk kereta dan di pantai
kegunaan rumah.
Teknologi yang digunakan itu boleh
digunakan untuk mencipta radio kereta
ataupun radio yang digunakan di tepi
pantai.