Why we have OOP concepts?

jitu108

Jitendra Gupta

Posted on March 1, 2021

Why we have OOP concepts?

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/

💖 💪 🙅 🚩
jitu108
Jitendra Gupta

Posted on March 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024