Object Oriented Programming
These days Object Oriented Programming has become the most preferred programming approach by software industries.
Previously world used to prefer Procedure Oriented Programming languages.
C language is the most popular Procedure Oriented Programming language.
But as C++ started using Object Oriented Programming approach, software industry started loving it because it seems to be very easy and deals effectively with the complexity of real-world problems.
Therefore we have also tried to explain Object Oriented Programming concepts by giving real-world examples.
Object is an actual physical existence of a Class. It is a real entity whose structure, identity and behavior are decided by a Class.
Class is just known as a template or a blueprint for an Object. It is used to decide structure, identity and behavior of an Object.
It can also be considered as a mould for an object.
Pillars of Object Oriented Programming (OOP)
Object Oriented Programming (OOP) is based on following main pillars,
Encapsulation means binding different things together.
Similarly, in Object Oriented Programming, encapsulation brings all fields and methods (functions) together and binds into single unit named Class which provides security as well.
It’s like a capsule which encapsulates its different ingredients together within a cover.
Similarly, Class brings all methods and fields (Class members) together and provides security so that outside world cannot access its member without authorization.
Abstraction means showing only essential aspects without including its details and ignoring the rest.
For example, a Car includes many engine parts, but they are hidden from us with the help of a car body because it is not necessary for us to drive a car. Only essential parts of a car like steering, brake, clutch & accelerator pedal, gear handle, etc. are kept open that are important for driving, without showing their details.
Similarly, abstraction enables Class to show essential aspects without including their details.
Abstraction is one of the important Pillar of OOP.
Inheritance is the process by which one class inherits/acquires the properties of another class.
It is similar to inheritance in living creatures.
In human beings, one human acquires the properties of another human through inheritance. That is, the child acquires some properties of its parents through inheritance as well as it contains its own properties.
Son/Daughter gets the wealth from its parents, grandparents, and so on. The wealth is transferred from generation to generation. This is also one of the important examples of inheritance.
Similarly, in Object Oriented Programming, properties from one Class to another Class are transferred as long as inheritance is continued.
Polymorphism is a mixture of two words poly and morphs taken from the Greek language.
Poly means many, morph means form.
In OOP the ability of an object to respond to the same process in different ways is called polymorphism.
Let’s look at a real-life example for better understanding.
A boy represents himself as a student in the classroom. The same boy represents himself as a Sportsman in ground and dancer at the dancing club.