OOPS Pillars

Encapsulation

Encapsulation refers to the bundling of data, along with the methods that operate on that data, into a single unit.

For example: Encapsulation is achieved when each object keeps its state private, inside a class. Other objects don’t have direct access to this state. Instead, they can only call a list of public functions.

If you want to communicate with the object, you should use the methods provided. But (by default), you can’t change the state.

Abstraction

Applying abstraction means that each object should only expose a high-level mechanism for using it.

This mechanism should hide internal implementation details. It should only reveal operations relevant for the other objects.

Abstraction hides complexity by giving you a more abstract picture, a sort of 10,000 feet view, clients are benefited with Abstraction because using abstraction it know what the supported functionalities are and does not how it is done and by whom. Interface is best example.

while Encapsulation hides internal working so that you can change it later.

In other words, Abstraction hides details at the design level, while Encapsulation hides details at the implementation level.

Inheritance

It means that you create a (child) class by deriving from another (parent) class. This way, we form a hierarchy.

The child class reuses all fields and methods of the parent class (common part) and can implement its own (unique part).

Polymorphism

Ability to process objects differently depending on their data type or class.

Polymorphism gives a way to use a class exactly like its parent so there’s no confusion with mixing types. But each child class keeps its own methods as they are.

As a simple example: If you have an interface and let's say 4 classes implement this interface. If you have method which takes interface as object parameter then client can pass any object of 4 available classes to this method without breaking the code.