Saurabh Srivastava | ibcoder.eth
IBCoder | Saurabh Srivastava

IBCoder | Saurabh Srivastava

What is Object-Oriented Programming and why you should learn it?

What is Object-Oriented Programming and why you should learn it?

Saurabh Srivastava | ibcoder.eth's photo
Saurabh Srivastava | ibcoder.eth
·Feb 23, 2021·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

There are multiple ways I could start this article by telling you about this paradigm's history and a bunch of other useless information and so, I won’t do that. I believe that the only useful information in technology is that what we can use to make our lives better today. Alright, now let’s begin.

The world is full of objects. Anything you see around you is an object. Each object has some intrinsic states and behaviors. Now, what if you could represent the objects in the real world as they are in your programs? That is what OOP is all about.

But why do it in the first place? You do it so that you don’t have to run around all over the place to look for something that relates to that one object. This makes it easier to maintain the code changes and extend the functionalities in the future.

Object-Oriented Paradigm has 4 basic principles under its belt:

  1. Encapsulation: Bundling states and behaviors into one single unit.
  2. Abstraction: Hiding your code implementation done in one of your classes from all other classes in order to reduce coupling.
  3. Inheritance: Using the features of super/parent class in the child class.
  4. Polymorphism: Using one object in many different forms.

Combine all the above and you will find some resemblance to what goes around in the world in one way or another. For example, take a Person object named John. John has many states like name, age, height, weight, etc. John has many behaviors like sleep, walks, eats, other private stuff, etc. These states and behaviors are all encapsulated inside John.

What about abstraction? Well, you interact with John and call his name. He responds to you back. You have no idea what is going on inside his head when he responded back to you [introvert trust issue awakens!]. His inner thoughts are hidden from the outside world. They are all abstracted away from the outside world.

Now John is also extremely rich. But he is still just a student who earns equivalent to the price of the air we breathe: 0. So, how is he rich? Because he inherited that wealth from his parents. There it is, the inheritance in full glory.

What about polymorphism? Well, let’s go a little bit philosophical here. I would like to use Hinduism Advaita understanding here but you are a Jivatma. Basically, the one who is born and will die. In this life, you will keep on taking multiple rebirths over and over again, until you come to the realization that you are one and all. Anyways, the dumb down version is that within a day you take many births and die many times, or keep changing your forms in terms of your role. In your home, you are a son, daughter, father, mother, etc. In college or office, you are a student or employee, etc. In this game of life, each person is playing some role in day-to-day life and thus changing forms from one situation to another.

In essence, we saw that the real-world entity, a Person named John, can be modeled through Object-Oriented Programming in such a simple way yet at the same time, in a highly complex manner. This simplicity and complexity are why one should pick up OOP as a skill and learn it.

Thank you for reading the article and have fun learning.

Share this