Concepts of OOPS ( Object Oriented Programming System ) in C++

concepts of oops in C++

Concepts of OOPS ( Object Oriented Programming System ) in C++

Different concepts of OOPS are  as follows

Object

Anything having some properties and behavior is called an object.

Example

Bike is an object having properties like color, make, model.

Behavior of bike includes speeding up the bike , applying brakes etc.

In C++, object is a variable of a class type.

Class

It is defined as collection of similar objects.

In C++, Class is considered a user defined data type that can contain two types of members:

i. variables known as data members

ii . Functions known as member functions

Abstraction

It is the way to represent essential things without going into background details.   Abstraction provides code and data security.

Example:

In real life, let us take example of a car, We only need to know how to start the car , increase speed and apply brakes but we are not concerned flow of fuel through different units of car.

In C++, abstraction can be provided by using access modifiers in classes  and by defining functions in header files

Encapsulation

Encapsulation is the process of combining data and functions under single unit. It prevents misuse of the data.

In C++, encapsulation is implemented  by using classes that can contain both data and functions.

By using encapsulation data hiding  is implemented so that data can’t be modified in unauthorized manner.

Members of class can be made private to prevent their access outside the class, hence providing data hiding

Inheritance

Inheritance is the process  of deriving properties and behavior of one object/class  by another object/class.

Inheritance is used to implement real life problems and relationships easily and quickly.

The main advantage of inheritance is that we can  reuse  existing code while developing new applications. So there is no need to start development from scratch

Inheritance has following types

  • Single Inheritance : One parent class and one child class.
  • Multiple Inheritance: One child class and more than one parent class.
  • Multilevel Inheritance: Child of one class is parent of another class.
  • Hierarchical Inheritance: One parent class and more than one child classes.
  • Hybrid Inheritance: Combination of all other types of inheritance. .

 Polymorphism

Polymorphism word is made of two words “POLY” and “MORPH”.

POLY means many and MORPH means forms.

It is the way to represent same thing in more than one form.

Example: 

Term PERIMETER is a single term that can be used to represent perimeter of a rectangle, circle or some other shape. In this way PERIMETER  term is associated with multiple things.

In C++ polymorphism is done by function overloading and operator overloading concepts.

Dynamic Binding

Dynamic binding is the process of linking the code with the function call  at runtime of the program.

In C++ dynamic binding is done by using function overriding along with virtual function.

Spread the love
Lesson tags: Abstraction in C++, Concepts of OOPS, Encapsulation in C++, Inheritance in C++, Polymorphism in C++, What is an object in C++, What is class in C++
Back to: C++ Programming Notes
Spread the love