Concepts of OOPS ( Object Oriented Programming System ) in C++
Different concepts of OOPS are as follows
Anything having some properties and behavior is called an object.
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.
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
It is the way to represent essential things without going into background details. Abstraction provides code and data security.
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 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 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 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.
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 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.