Four Pillars of Object-Oriented Programming (OOP)

Moushumi Pardesi
2 min readMay 27, 2021

--

Before OOP we had procedural programming that divided the program into a set of functions. So we have data stored under variables and functions operate under data. This is a very simplistic way of programming and often what you will be introduced to, as a beginner in programming.

But as programs larger and more complex, there will be too many functions that have to copied and paster every time you need them. If you make a change to one function, then several others break. This is something we frown upon and call spaghetti code.

Too much interdependency between all the functions makes the overall code unclear and jumbled up — like spaghetti.

OOP solved this problem by encapsulating related variables and functions into a unit. Such a unit is called an object. In an object, the variables are called properties, and functions are called methods. This is called encapsulation.

Another pillar of OOP is abstraction. Imagine turning on your laptop using its power button — all the logic boards, etc. are hidden from you. Similarly, in code, you can hide most of the properties and methods so the interface is simpler. Also, making changes would not leak to the outside. You may delete a method or change its parameters, but none of these will impact the rest of the application’s code.

Inheritance is a mechanism that helps you eliminate redundant code. Several methods and properties that are useful for more than one set of elements can be defined once and used over and over again.

In OOP, Polymorphism allows you to get rid of many long if and else type statements. Poly means many and morph means forms.

In summary:

Encapsulation reduces complexity + increase reusability

Abstraction reduces complexity + isolates the impact of changes

Inheritance eliminates redundant code

Polymorphism refactors ugly switch/case statements

--

--

Moushumi Pardesi
Moushumi Pardesi

Written by Moushumi Pardesi

Fixed Income Index Researcher at JP Morgan & Chase

No responses yet