Four Pillars of Object Oriented Programming

Nicholas
3 min readMar 31, 2021

--

When you are learning how to program one of the popular concepts that will come up a lot is object oriented programming (OOP). I learned that object oriented Programming is an important to concept to understand in order to show an understanding of what programming is and that you are ready to move on to bigger things. As a refresher I want to go over the four pillars of OOP for better understanding of the concepts and how they work.

At the start when you learn how to code you probably learned Procedural programming. This method is more focused on functions rather than objects. In Procedural Programming it is much harder to code because it is harder to incorporate new functions or change a function because all the code is dependent on each other. so in order to get past this hurdle you would have to learn a new way to program Object Oriented Programming. OOP has four main pillars that you need to understand and they are Abstraction, Encapsulation, Inheritance and Polymorphism.

Abstraction

The metaphor that I have heard a lot in order to describe Abstraction is modern technology. For example a TV has a bunch of complex technology a normal person would not know how to use on the inside but there are a couple of buttons on the outside that would allow you to turn it on, change the channel, change the input etc. The way this would be applied in programming is by hiding functions and variables inside of an object in order to make the interface look simple. By putting these functions and variables into an object this will isolate the code from all other code, hereby making it easier to make changes without affecting other code in your application.

Encapsulation

Now that you understand abstraction maybe it will be a little easier to understand Encapsulation. Encapsulation is putting all the variables and functions associated with an object into that object. So let’s say we are programming a character in a video game, and let’s name the character object Spiderman. Some variables we could put into the object, Spiderman, are his name Peter Parker, his alter-ego Spiderman and his height 5'10". Some functions we could put into the Spiderman object are shootWeb(), climbWall(), and punch(). So all these variables are associated with the Spiderman object and you can change any of them without worrying about it affecting any of the other objects in the application you are building.

Inheritance

The next pillar or Object Oriented Programming is Inheritance. The key purpose of this pillar is to eliminate redundant code. So if you would want to give a bunch of object the same variables and functions you would define a generic object with all of the variables and function that you want these objects to inherit and just let all the objects inherit the variables and functions instead of retyping them for each of the objects.

Polymorphism

The final pillar of Object Oriented Programming is Polymorphism. The purpose of polymorphism is to get rid of long if else statements. So if we look back at inheritance and if all of the objects inherited a click method but you do not want all the clicks to operate the same way. So you would redefine what you would want the object, that would act differently, to do for the click function.

Those are the four pillars of Object Oriented Programming. I hope it helped!

--

--

Responses (1)