BASICS OF
OBJECT
ORIENTED
PROGRAMMING
WHAT IS PROGRAMMING?
Programming is the process of giving instructions to the
computer to perform the desired task.
TYPES OF PROGRAMMING
There are two types of programming paradigms:
PROCEDURAL PROGRAMMING OBJECT ORIENTED
PROGRAMMING
Program is broken down into
functions or subprograms
Program is broken down into objects.
Functions/subprograms work on data.
Data can move freely from function to
function.
Data and its associated functions are
bundled into independent entity.
Data is kept hidden and secured.
It follows top-down approach. It follows bottom-up approach.
Examples: COBOL, Basic Example: Java
NOTE: C++, C sharp, Object Pascal etc. are the languages which support procedural as
well as object oriented paradigm.
Function
1
Local
data
Function 2
Local data
Function
3
Local data
Function 4
Local data
Function 5
Local data
Global data
Main program
OBJECT1
DATA
FUNCTION
S
OBJECT3
DATA
FUNCTION
S
OBJECT
2DATA
FUNCTION
S
TYPES OF PROGRAMMING Contd…
PROCEDURAL PROGRAMMING
OBJECT ORIENTED PROGRAMMING
•The data of an object can be accessed only
by the functions associated with that object.
•However, functions of one object can access
the functions of other objects.
•The data defined inside a function is accessible only by
that function and is called local data of that function.
•The data defined above functions is called Global Data
and is accessible by all functions which are defined below
it.
FEATURES OF OBJECT ORIENTED PROGRAMMING
DATA HIDING, DATA ABSTRACTION, DATA
ENCAPSULATION The process of hiding the data from the outside
world is called DATA HIDING.
 The ability to represent data at very conceptual
level without showing details. It refers to
representing only essential features and hiding the
background details is called DATA ABSTRACTION:
.
 The wrapping up of data and methods that operate
on that data in a single unit is called DATA
ENCAPSULATION. It keeps data both safe from
outside interference and misuse.
 For example, We don't need to know the internal
working of the mobile phone to operate it. We have
an interface to use the device behavior without
Internal machinery of
mobile phone which
is hidden from the
user
External
interface to
operate the
device
FEATURES OF OBJECT ORIENTED PROGRAMMING
Contd…..
DATA HIDING, DATA ABSTRACTION, DATA
ENCAPSULATIONThe mobile phone contains both data and operations that can be
performed on that data. Both data and its associated operations are
bundled together in a single unit i.e. phone. This is called
ENCAPSULATION.
The internal machinery of the phone is hidden from the user , this is
called DATA HIDING.
Only the interface of the phone is available to the user to perform
operations on the phone and rests of the things like machinery etc. are
hidden. This is called DATA ABSTRACTION.
FEATURES OF OBJECT ORIENTED
PROGRAMMING
INHERITANCE
NOTE: All the above features of Object Oriented Programming are implemented with the help
of classes and objects.
 It is feature by which one class acquires the features of an already
existing class.
 Inheritance is a process of creating new class (derived class /sub class /
child class) from existing class (base class / super class / parent class).
 The derived classes not only inherit capabilities of the base class but also
can add new features of their own.
Advantage of Inheritance:
It allows reusability of code. Reusability of code saves money as well as
time and increases program reliability.
To include features of already existing class (debugged) in a new class.
Child class can use the properties and methods of base class.
FEATURES OF OBJECT ORIENTED
PROGRAMMING Contd…
INHERITANCE
NOTE: All the above features of Object Oriented Programming are implemented with the help
of classes and objects.
EXAMPLE:
When the mobiles were first
introduced its basic functionality
was to make and receive calls
and messages.
With every new version of mobile
phone some new features are
added retaining the basic
features.
FEATURES OF OBJECT ORIENTED PROGRAMMING
POLYMORPHISM It means one thing having many forms.
 It is an ability of a method/operator to execute in many forms.
 It is a provision by which an operator or a method exhibits different
characteristics depending upon different sets of input provided to it.
NOTE: All the above features of Object Oriented Programming are implemented with the help
of classes and objects.
POLYMORPHISM
METHOD OVERLOADING
Multiple methods with same method
name which are differentiated on the
basis of different type or number of
arguments.
OPERATOR OVERLOADING
Same operator works
differently in different situation.
FEATURES OF OBJECT ORIENTED PROGRAMMING
Contd….
POLYMORPHISM
EXAMPLES:
 The camera feature of a phone has different modes like slow
motion, photo, video, panorama etc. The functionality of camera is
different depending upon the modes chosen. We can say camera
feature is behaving differently in different modes.
 The SendMessage feature of a mobile phone can be used to send
message to a single person or to multiple people.
NOTE: All the above features of Object Oriented Programming are implemented with the help
of classes and objects.
COMPONENTS OF OBJECT ORIENTED
PROGRAMMING
 CLASS: A class is a group of objects with same attributes and
common behaviors. It is a blue print to create objects.
 OBJECT: An object is an instance of a class that is capable of
holding actual data in memory.
Class and object are related to each other in the same way as data
type and variable. If class is a data type then object is a variable of
that data type.
NOTE: Each object is an entity which has certain properties(data members) and behaviors (methods).
Memory is allocated to the objects and not to the class.
COMPONENTS OF OBJECT ORIENTED
PROGRAMMING Contd…..
 Each object is an entity which has certain attributes/properties(data
members) and behaviors (methods). Memory is allocated to the objects
and not to the class.
 DATA MEMBERS AND METHODS: Data members are used to store
information and methods contain code to perform a particular task.
 ACCESS SPECIFIERS/ VISIBILTY MODES: They are classified as:
 Private
 Protected
 Public
Usually data members are kept in private or protected visibility
modes and methods are kept in the public mode.
NOTE: Members in the private and protected sections of the class are not accessible outside the
class.
COMPONENTS OF OBJECT ORIENTED
PROGRAMMING Contd…..
Examples from real life:
 Animal is a class and dog is an object of this class.
 Phone is a class and iphone is an object.
CLAS
S
OBJE
CT
PROPERTIES
(DATA
MEMBERS)
METHOD
S
Anima
l
dog color Walk()
Bark()
Eat()
Run()
CLASS OBJEC
T
PROPERTIES
(DATA
MEMBERS)
METHODS
Car iphone Make Make_Call()
Year Receive_Call()
color Message()
model Camera()
Price Calculator()
MESSAGE PASSING
In OOP objects send and receive messages in the same way as
human beings. A message for an object is the request for the execution
of a function.
 When a program is executed, the objects interact by sending
messages to one another. Functions of one object can access the
functions of other objects.
For example, if LIBRARY and MEMBERS are two objects in a program,
then the member object can send the request to the library object
requesting for the issue/return of books.
Objects can interact with each other without the details of each other’s
data.
It is sufficient to know the type of message accepted and type of
response returned by the objects.
ABSTRACT CLASS
Abstract class: The classes for which it is not essential to
declare objects to use them are known as abstract classes.
They are normally used as base class in inheritance for
which no direct object is required to be created.
They are used for defining generic methods where there
is no requirement of storing results.
They don’t have data members.
Concrete class: The classes for which objects are required
to be declared are known as concrete classes.

Basics of object oriented programming c++ [autosaved]

  • 1.
  • 2.
    WHAT IS PROGRAMMING? Programmingis the process of giving instructions to the computer to perform the desired task.
  • 3.
    TYPES OF PROGRAMMING Thereare two types of programming paradigms: PROCEDURAL PROGRAMMING OBJECT ORIENTED PROGRAMMING Program is broken down into functions or subprograms Program is broken down into objects. Functions/subprograms work on data. Data can move freely from function to function. Data and its associated functions are bundled into independent entity. Data is kept hidden and secured. It follows top-down approach. It follows bottom-up approach. Examples: COBOL, Basic Example: Java NOTE: C++, C sharp, Object Pascal etc. are the languages which support procedural as well as object oriented paradigm.
  • 4.
    Function 1 Local data Function 2 Local data Function 3 Localdata Function 4 Local data Function 5 Local data Global data Main program OBJECT1 DATA FUNCTION S OBJECT3 DATA FUNCTION S OBJECT 2DATA FUNCTION S TYPES OF PROGRAMMING Contd… PROCEDURAL PROGRAMMING OBJECT ORIENTED PROGRAMMING •The data of an object can be accessed only by the functions associated with that object. •However, functions of one object can access the functions of other objects. •The data defined inside a function is accessible only by that function and is called local data of that function. •The data defined above functions is called Global Data and is accessible by all functions which are defined below it.
  • 5.
    FEATURES OF OBJECTORIENTED PROGRAMMING DATA HIDING, DATA ABSTRACTION, DATA ENCAPSULATION The process of hiding the data from the outside world is called DATA HIDING.  The ability to represent data at very conceptual level without showing details. It refers to representing only essential features and hiding the background details is called DATA ABSTRACTION: .  The wrapping up of data and methods that operate on that data in a single unit is called DATA ENCAPSULATION. It keeps data both safe from outside interference and misuse.  For example, We don't need to know the internal working of the mobile phone to operate it. We have an interface to use the device behavior without Internal machinery of mobile phone which is hidden from the user External interface to operate the device
  • 6.
    FEATURES OF OBJECTORIENTED PROGRAMMING Contd….. DATA HIDING, DATA ABSTRACTION, DATA ENCAPSULATIONThe mobile phone contains both data and operations that can be performed on that data. Both data and its associated operations are bundled together in a single unit i.e. phone. This is called ENCAPSULATION. The internal machinery of the phone is hidden from the user , this is called DATA HIDING. Only the interface of the phone is available to the user to perform operations on the phone and rests of the things like machinery etc. are hidden. This is called DATA ABSTRACTION.
  • 7.
    FEATURES OF OBJECTORIENTED PROGRAMMING INHERITANCE NOTE: All the above features of Object Oriented Programming are implemented with the help of classes and objects.  It is feature by which one class acquires the features of an already existing class.  Inheritance is a process of creating new class (derived class /sub class / child class) from existing class (base class / super class / parent class).  The derived classes not only inherit capabilities of the base class but also can add new features of their own. Advantage of Inheritance: It allows reusability of code. Reusability of code saves money as well as time and increases program reliability. To include features of already existing class (debugged) in a new class. Child class can use the properties and methods of base class.
  • 8.
    FEATURES OF OBJECTORIENTED PROGRAMMING Contd… INHERITANCE NOTE: All the above features of Object Oriented Programming are implemented with the help of classes and objects. EXAMPLE: When the mobiles were first introduced its basic functionality was to make and receive calls and messages. With every new version of mobile phone some new features are added retaining the basic features.
  • 9.
    FEATURES OF OBJECTORIENTED PROGRAMMING POLYMORPHISM It means one thing having many forms.  It is an ability of a method/operator to execute in many forms.  It is a provision by which an operator or a method exhibits different characteristics depending upon different sets of input provided to it. NOTE: All the above features of Object Oriented Programming are implemented with the help of classes and objects. POLYMORPHISM METHOD OVERLOADING Multiple methods with same method name which are differentiated on the basis of different type or number of arguments. OPERATOR OVERLOADING Same operator works differently in different situation.
  • 10.
    FEATURES OF OBJECTORIENTED PROGRAMMING Contd…. POLYMORPHISM EXAMPLES:  The camera feature of a phone has different modes like slow motion, photo, video, panorama etc. The functionality of camera is different depending upon the modes chosen. We can say camera feature is behaving differently in different modes.  The SendMessage feature of a mobile phone can be used to send message to a single person or to multiple people. NOTE: All the above features of Object Oriented Programming are implemented with the help of classes and objects.
  • 11.
    COMPONENTS OF OBJECTORIENTED PROGRAMMING  CLASS: A class is a group of objects with same attributes and common behaviors. It is a blue print to create objects.  OBJECT: An object is an instance of a class that is capable of holding actual data in memory. Class and object are related to each other in the same way as data type and variable. If class is a data type then object is a variable of that data type. NOTE: Each object is an entity which has certain properties(data members) and behaviors (methods). Memory is allocated to the objects and not to the class.
  • 12.
    COMPONENTS OF OBJECTORIENTED PROGRAMMING Contd…..  Each object is an entity which has certain attributes/properties(data members) and behaviors (methods). Memory is allocated to the objects and not to the class.  DATA MEMBERS AND METHODS: Data members are used to store information and methods contain code to perform a particular task.  ACCESS SPECIFIERS/ VISIBILTY MODES: They are classified as:  Private  Protected  Public Usually data members are kept in private or protected visibility modes and methods are kept in the public mode. NOTE: Members in the private and protected sections of the class are not accessible outside the class.
  • 13.
    COMPONENTS OF OBJECTORIENTED PROGRAMMING Contd….. Examples from real life:  Animal is a class and dog is an object of this class.  Phone is a class and iphone is an object. CLAS S OBJE CT PROPERTIES (DATA MEMBERS) METHOD S Anima l dog color Walk() Bark() Eat() Run() CLASS OBJEC T PROPERTIES (DATA MEMBERS) METHODS Car iphone Make Make_Call() Year Receive_Call() color Message() model Camera() Price Calculator()
  • 14.
    MESSAGE PASSING In OOPobjects send and receive messages in the same way as human beings. A message for an object is the request for the execution of a function.  When a program is executed, the objects interact by sending messages to one another. Functions of one object can access the functions of other objects. For example, if LIBRARY and MEMBERS are two objects in a program, then the member object can send the request to the library object requesting for the issue/return of books. Objects can interact with each other without the details of each other’s data. It is sufficient to know the type of message accepted and type of response returned by the objects.
  • 15.
    ABSTRACT CLASS Abstract class:The classes for which it is not essential to declare objects to use them are known as abstract classes. They are normally used as base class in inheritance for which no direct object is required to be created. They are used for defining generic methods where there is no requirement of storing results. They don’t have data members. Concrete class: The classes for which objects are required to be declared are known as concrete classes.