Object Orientated Programming Concept; The better way: Part 2 four paradigms of OOP

Md. Taiful Islam Tomal
5 min readOct 25, 2018

--

This is the second and last part of this series. If you missed the first one please read from below link

Object Orientation has four major paradigms

  1. Inheritance
  2. Abstraction
  3. Polyphormism
  4. Encapsulation

Inheritance

Inheritance is the way, one object acquires the properties and functionalities of another similar type object. Inheritance in OOP is quite different from the Inheritance from a living substance. We are no object. Don’t just compare both of them, programming has nothing to do with living. In living-substance parents are responsible for creating their own child, but in OOP parent don’t even know whose is going to be his child. Now look at the below picture

The image was taken from World Mysteries — Blog

You can see 100 years of car revolution. Ignore the train. In 1900 people created the car that had three wheels, now people 1920 create another car that was an extended version of 1900 cars. But they both have the same purpose and functionalities yet 1920 was quite advanced from 1900 model. In 2000 people created a really advanced car with more speed, comfort and many more features that was extended from the 1980 model. So every car model inherits from the immediate previous car model and adds its own functionalities. But the interesting fact is 1900 model had no idea then how the car will be in the year 2000. That’s why in the object world, the parent doesn’t really know about their children. Another possible scenario, Let’s say the 1980 model doesn’t want to inherit the 1960 model, rather than it wants to inherit 1920 model and make a modern car from more raw scratch.

Now let’s say 1900 is the base car and every other car was inherited from that car. Numerous other car was inherited from 1900 car. So a parent object can have many child objects. But at the end of the day, they all are cars. A car can’t extend from a boat. What is not possible in the real world also not possible in the object world. Suppose you got a car from your father that can be an inherited property but if you got a car from your friend that will be simple transfer and that would nothing to do with inheritance.

The image was taken from newsin.asia

So to summarize, Inheritance is the way to extend an existing Object and make a better or powerful one. Parent and child will always be the same object, no matter what. Parent has the power to control how much it wants to share with its child.

Abstraction

Can you recognize the element from the below picture?

The image was taken from The Lincoln County News

Sure you do. It’s a bird. But did you know this bird before, or know its name. Maybe yes. But most of you won’t. It is a very rare bird. But how do you know its a bird? Its because you have a prototype or idea of birds in your mind. Anything looks like that idea must be a bird.

The image was taken from Dreamstime.com

Now if you think carefully there is no actual object that is a bird, rather than its a concept or idea how the actual bird is like. We can recognize any bird like pigeon, cuckoo or any other bird using that concept. Vegetables can be another example. Vegetables is no actual thing, but we use the idea of vegetable to recognize eggplant, carrot, cucumber etc.

So Abstraction is an idea in OOP world that how an object can be built. It’s a concept rather than an actual or concrete Object. That’s why we can’t create an Object of an abstract class. But we can create any customize object of our choice using that concept. Inheritance and Abstraction go in hand in hand. As abstraction is the concept, you need inheritance to complete that concept and make a concrete object.

The important thing is to remember that hiding code or implementation is not an abstraction, at least not in OOP world. Abstraction has really broad meaning. Sometimes hiding implementation may be referred to as the abstraction, that is true in general sense but that really has nothing to do with OOP. That’s just normal abstraction in general.

Btw the name of the bird was vermilion flycatcher.

Polymorphism

Polymorphism is the behaviour of an Object under the different situation. It’s a great feature in OOP. A capable object can behave differently under the different scenario. For example, you behave formally with your teacher but informal with your friends and family. We behave differently in office compare to at the home. An object also can have this kind of capabilities and that is Polymorphism in OOP.

Encapsulation

Encapsulation is the data integrity in an object. We may have many objects in the OOP world. Each Object holds its own data and data between object never overlaps. If you call a method of an object that will only and only modify or return the data of that object. That’s is encapsulation in OOP.

That’s all for OOP in a brief way. One can understand OOP in many ways, this is just one way to understand this. But since the object that matters, we should think the fundamentals of OOP in object perspective, not class perspective.

Hope you enjoy reading this :). Please feel free to leave your feedback.

--

--