The Basics - Four Pillars of Object Oriented Programming

What are the four pillars of OO programming? (Summary)

a.       Inheritance 

                                                                           i.      (e.g. object triangle inherits from object shape)

b.      Abstraction

                                                                           i.      Expose relevant functions and hides irrelevant, abstract complexity, a wrapper, private vs public properties.

c.       Polymorphism

                                                                           i.      Many forms,  one interface having many behaviours. Invoke base class in a child clase.

d.      Encapsulation

                                                                           i.      Methods and functions are encapsulated in a class.

Detailed version:

1. Abstraction

Abstraction is a process of exposing essential features of an entity by hiding the other irrelevant details. Abstraction mainly reduces complexity and increases efficiency. An entity can have multiple abstractions.

2. Encapsulation

Encapsulation is the process of putting data and the operations (functions) that can be performed on that data into a single container called class. Now, any programmer can use this class without knowing how it is implemented. Due to encapsulation, data is insulated, thus not directly accessible from the outside world. This is known as Data Hiding.

Remember, Encapsulation is not data hiding, but, Encapsulation leads to data hiding.

3. Inheritance

In a nutshell, inheritance is a process of creating new class from the existing one. The new class may have some additional properties and functionalitiy.

4. Polymorphism

Poly means many and Morphs means forms. Polymorphism refers to the ability to take multiple forms and it allows us to invoke derived class methods through a base class reference during run-time.

This article is part of the GWB Archives. Original Author: NETCode

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.