Why we have OOP concepts?
Published: 2021-03-01 16:53:41

OOP has been ruling the software development world for long. Object Oriented Programming tried to emulate real-world scenarios.

#Class
In real world we see _**things**_ which have been replicated from a _**blueprint**_. All human have more-or-less common features like limbs, head, body and they can walk, talk, breathe and think – barring the exceptions (no offence to the especially-abled). This blue-print has been emulated as **class** or **struct** in OOP, and the replicas of the blue-print are called **objects**.

#Encapsulation
Apart from limbs-head-body, human have whole structure of skeletal-system, muscular-system, respiratory-system, nervous-system and so on. But we neither know them (when we see a person), nor care for. This same concept is known as **Encapsulation** in OOP which advocates _**hiding of the processes and information which are not relevant to the outer world**_, to make thing less complex for them.

There is a saying –

>Magic does not happen on the stage, but in the details which are hidden.

The same magic is done in OOP by _**hiding the things which help achieve the objective**_ and it we call as **Data Hiding**. There are a lot of things up above the sleeves of a magician which help him perform the magic. Similarly, there could be raw-material or intermediate-products which are required to produce the final result. These could be some variables which are just to sit there in an object and do the dirty job. And these _**must be hidden with proper access modifiers**_.

#Abstraction
Humans of different continents and climates differ but we can draw some similarities among them and so, no wonder, we call all them Human. They might be called Indic, Dutch or German but they all are Human and have derived their fundamental properties from Homo Sapience. in OOP, _**aggregation of common properties**_ of all these ethnic group is called Abstraction. Abstraction is _**going up the hierarchy**_ and _**generalizing**_ common properties.

#Inheritance
Further, I have inherited many commonalities from my father. I may look like my father and many a times a child inherits intelligence from their parents too. But I might not inherit his profession. He may be carpenter, but I may chose to be a travel-blogger. Apart from being travel blogger, in all other aspects I am like my father. So, in all essence, I have _**inherited**_ their properties. Right, in OOP this _**borrowing of properties from things higher up in lineage**_ is called Inheritance. The properties which did inherit but replaced them with mine are called _**newing-up a property or method in OOP**_.

#Polymorphism
Now there is a case. I might be a travel-blogger, but on the weekends I teach children Mathematics. (it’s ridiculous. How can a travel blogger be there to teach every Sunday. But for the sake of considering, let’s consider it).

So now, there can come 3 works – carpentry, blogging and teaching to our house. Based on the scenario it will either be handled by my father or me. If it is carpentry – it must be handled by my father. If it’s blogging or teaching, it will be handled by me. So, same action **Work** has three different kinds for us. The _**existence and handling of same function differently**_ is called **Polymorphism** in OOP.

If Polymorphism is handled by same class – it is static polymorphism or **Overloading**. If it is handled by any of the members of the family, but not sure who, it is dynamic polymorphism or **Overriding**.

_Abstraction, Inheritance, Encapsulation and Polymorphism are called the 4 pillars of OOP._

When thought in terms of OOP, the software applications are more related to the real-world. This closeness to real-world had given genesis to many concepts which make developer-client understanding better and delivery of better quality software.

http://blog.jitendragupta.info/index.php/2021/02/26/why-we-have-oop-concepts/