What is Object-Oriented Programming?
The OOP programming approach is based on fundamental concepts of class and object.
OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects.
There are many object-oriented programming languages including JavaScript, C++, Java, and Python.
It is programming style which is associated with concepts of class and object and various other concepts like:
Inheritance
polymorphism
abstraction
Encapsulation etc
Program are divided into small modules known as classes.
Function and data are tied together in an object.
2. Course Contents
What Procedural Oriented Programming Language?
What is OOP?
Introduction to OOP
Introduction to C++ programming
Classes and Object
Principles of Object Oriented programming
1. Inheritance
2. polymorphism
3. Encapsulation
4. Data abstraction
Benefits of object oriented Programming
2
3. What is Procedural
Programming Languages?
• Is standard programming approach,
used by language such as C,Fortran
and Basic.
• Tells computer “what to do?” and
“How to do it ?”
• involves the steps that must be
followed to accomplished a specified
tasks .
Fig: Typical Structure of Procedure Oriented Programs
3
4. The programming paradigm for procedural programming language is
1. Decide which procedure you want:
2. use the best algorithm you can find.
we can say the procedure programming language focuses on algorithm or procedure
to perform a particular job.
Large programs are divided into smaller programs called functions.
Data move openly around the system from function to functions.
4
5. int main(){
int a;
int b;
printf(“enter first value n”);
scanf(“%d”,&a);
printf(“enter second value n”);
scanf(%d”, &b);
………
}
5
• Step by Step entry of list of
instruction.
And this approach was called Structural
or procedural programming
languages where instructions was
passed in certain procedure.
Growing Complexity and size code
there need somthing more
convenient and there start OOP.
6. What is Object-Oriented Programming?
The OOP programming approach is based on fundamental concepts of class and
object.
OOP allows decomposition of a problem into a number of entities called objects and
then builds data and functions around these objects.
There are many object-oriented programming languages including JavaScript, C++,
Java, and Python.
6
7. Introduction to OOP
It is programming style which is associated with concepts of class and object
and various other concepts like:
1. Inheritance
2. polymorphism
3. abstraction
4. Encapsulation etc
Program are divided into small modules known as classes.
Function and data are tied together in an object.
7
9. Introduction to C++
• C++ is a general purpose programming language that was developed as the
enhancement of the C language t include object-oriented paradigm. The basics
syntax and code structure of both C and C++ are the same.
• C++ was developed by Bjarne Stroustrup at bell lab in 1979 and commonly called as
“C with Classes”
• It is simple language that program can be divided down into logical units and parts
has rid library support and variety of data types.
• C++ supports the four primary features of OOP : encapsulation, polymorphism,
abstraction, and inheritance.
• A function is a minimum requirement for a C++ program to run.
9
10. • the program to display message “welcome to c++!!” in screen using c++ can be
written as :
#include <iostream.h>
void main()
{
cout<<“welcome to c++!!”;
}
10
11. Classes
A class represent the group of objects that share common properties, behavior and
relationships.
It is an abstract blueprint used to create more specific, concrete objects.
For examples: The name ‘Computer’ can be class that represent personal
computer, lab computer and computer with similar characteristics.
Thus a class is an identifier which is general name i.e family/group name defined to
represent object of similar characteristics.
11
12. What does a class define
ATTRIBUTES
• name
• height
• weight
• gender
• age
BEHAVIOUR
• Walk
• run
• jump
• speak
• sleep
• Attributes are characteristics described by the class
and behavior describe what a class can do.
• For example If we are describing the class person
then its attributes are name height weight then its
behavior is walk run jump and so on.
• Attributes and Behavior in most of case are describes
as properties and methods .
• Class is describing them in a abstract i.e if class say a
person has a name and has height but does not say
what a name is because a class is description of
something
PROPERTIES
• name
• height
• weight
• gender
• age
METHODS
• Walk
• run
• jump
• speak
• sleep
12
13. • A class definition starts with keywords class followed by class name; and class body , enclosed by a pair of curly braces. It
must be followed by semicolon at the end.
class class_name
{
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
protected:
variable declaration;
function declaration;
};
Declaration of class
13
14. Objects
• An object is a real world entity with some characteristics and behavior. The world is
full of object such as pen, lamp, house, car, dog, cat and so on.
• Each object has unique identity and a states.The states of an object is define by
member variables.The object behaviors is defined by its member methods.
• It is an instances of classes .Creating the object is like defining a variable of a data
type.
• Once the class has been declared, we can create variables of that type by using the
class name.
• An object does not exits until the class has been created ; the class is just definition.
14
15. when a object is physically created, space for that object is allocated in primary
memory. It is possible to have multiple object of the class.
syntax of creating object:
class_name object_name;
e.g.
Box b1; // assume box as a box name
the statement Box b1; creates a variable b1 of type Box.The variable b1 is known as
object of the class Box. Thus, class variables are known was object.
We can create multiple object of the class as follows:
Box b1, b2, b3 ;
Syntax of creating the object
15
16. Principles of Object Oriented Programming
• The OOP programming is based on the four major fundamental principles.The OOP
principles includes:
1. Encapsulation
2. Inheritance
3. Abstraction
4. Polymorphism
16
18. 1. Inheritance
• The inheritance is the process of acquiring the existing functionality odf the parent
class and adding additional features and functionality in to zither inherited child class.
• It is the process of deriving one class from another class. The existing class is known
as base class, super class or parent class and the newly created class is known as
derived class, child class and sub class.
• The derived class inherits all the features, expect private members inherent in the
base class.Inheritance supports the properties of code resuability and reliability
18
19. For examples
We can create base class named FRUIT and
define derived class as MANGO, ORANGE,
BANANA etc.
Each of them have common characteristics
like taste, price and season. The common
characteristic are in Base class. Each of the
characteristics are in derived class with
additional features or attributes.
MANGO would have its own defined feature,
ORANGE would have its own features and
BANANA would have its owns feature and so
on .
Figure:Child classes of the classes
21. 2. Polymorphism
• The word poly means many and morphe means forms.
• Polymorphism means the ability to take more than one form.
• The function overloading, operator overloading, function overriding, virtual function
are the examples of polymorphism.
• In function overloading two or more functions have same name but with different
parameters are used.
• In function overriding, two or more function, with same name and same parameter but
one defined in base class and other in child class are used.
21
22. 22
• The polymorphism can be defined
ass singe object as single object
with multiple behavior.
• the common use of polymorphism in
OOP occurs when a parent class
reference is used to refer to a child
class object.
• the common and simple use of
polymorphism in OOP program is
the use of same method name.
• For example, define many method
with same method name but
different implementation.
23. The process of binding the data and
methods together as a single unit is
referred as encapsulation.
It prevents the data from
unauthorized use from other parts of
program.
23
3. Encapsulation
24. • Mechanism to hide the member of the class and providing the access to only some of
them.
• We can make member of class private , public and protected. The outside world
cannot access those member which have been made private and the public member
can be accessed from the class as well was from outside the class.
• In this way class can hide some member from outside the world and provide the
security to them.
Data Hiding
24
25. 4. Data Abstraction
• Abstraction refers as an act of representing essential features with out including
background details or explanation.
• It is methodology that supports use of compound or complex object without its detail
knowledge
• simply it refers to hiding the complexity.
• For examples
• A Class car is made up of an engine, gearbox, steering object and many more
components of the car work internally but only how the interface with them i.e
message to them ,receiving message from them
25
26. Benefits of Object Oriented languages
Better code reusability using object and inheritance.
Principles of data hiding helps build secure system.
Multiple objects can coexist without any interference.
Software complexity can be easily managed.
26