DEV Community

Cover image for Four Pillars of OOP
pharia-le
pharia-le

Posted on

Four Pillars of OOP

A brief overview of the four pills of Object-Oriented Programming (OOP)

Question

What are the four pillars of OOP?

Answer

The four pillars of OOP are encapsulation, abstraction, inheritance, and polymorphism.

Encapsulation

  • Encapsulation is the idea of containing the attributes and behaviors of a class within itself. The state is secured and is private to the class. Only the object itself can update the state, and other objects only have access to the object's state through public methods.

Abstraction

  • Abstraction is the way in which we select and present the pertinent information for an object. All the mechanisms under the hood need not be presented, but the high-level data will be.

Inheritance

  • Inheritance is a way in which an object acquires some/all of the properties of another object. It is a great way to reuse code and build on top of previously created objects.

Polymorphism

  • Polymorphism is distinct from inheritance because the object acquires some/all of the properties of another object, but the object will maintain its own unique methods and functions.

Conclusion

The four pillars are fundamental to OOP. Commit them to memory!

& Remember... Happy coding, friends! =)

Top comments (1)

Collapse
 
eljayadobe profile image
Eljay-Adobe

In contrast, for FP, the pillars (as I see them) are:

  • immutability
  • recursion
  • pattern matching
  • higher-order functions
  • code as data
  • separation of behavior from data
  • referential transparency