Unit 2 - OOP - 1
Unit 2 - OOP - 1
Structured OOP
Focuses on Focuses on
Process Object
Follows Top Down Follows Bottom
Approach Up Approach
Fundamentals of object-oriented programming
◦ objects
◦ classes
◦ data members
◦ methods
◦ messages
◦ data encapsulation
◦ data abstraction and information hiding
◦ inheritance
◦ polymorphism
Object
◦ Objects are basic run time entities.
◦ e.g. person, a place, a bank account, or any item that the program has to
handle.
◦ Each object take up space in the memory to store data and code.
◦ OOP encapsulates data (attributes) and functions (behavior) into
packages called objects. Objects have the property of information
hiding.
◦ Representation of object
◦ Objects Interact with each other by sending messages to each other.
• Class
◦ A class is a blueprint or prototype that defines the data members and the
methods (functions) common to all objects of a certain kind.
◦ Objects (data and functions) are members of user-defined types called
classes.
◦ A class definition is an extension of a C structure definition , made up of
declarations of variables and of function
◦ The variables are typically declared to be private or protected and the
functions are typically declared to be public.
◦ structures members are public by default and class members are private
by default.
Example : Objects and Classes
object class
class Student
char name
int rollNo
setName()
Rani Rima Rita Bina setRollNo()
R001 R003 R004
R002 calcMarks()
Program is composed of a collection of individual units or
objects, as opposed to a traditional view in which a program is
a list of instructions to the computer.
Object B
Data variable
Object A Object C
Member
Function
Data variable Data variable
Member Member
Function Function
• Data members
◦ Attributes of object.
◦ The variables are typically declared to be private or protected
• Methods or member functions or messages
◦ Functions operate on class data.
◦ functions are typically declared to be public.
◦ Defined outside or inside class.
◦ Objects communicate with each other.
Encapsulation
◦ The process of binding code and data together in the form of a capsule
◦ Data is not accessible to the outside world, only those function which are wrapped in
the class can access it.
◦ Since the classes use the concept of data abstraction, they are known as Abstract Data
Type(ADT).
◦ EXAMPLE-tv
Name
Gender
Age