The 4 Pillars of OOP

Object oriented programming (OOP) is a framework used in programming languages, such as Java and python, that is based on the concept of “objects”. The OOP framework is characterised by 4 features that are often referred to as “pillars” to emphasise their importance: Encapsulation, Abstraction, Inheritance and Polymorphism.

Encapsulation

Encapsulation describes the act of organising data and functions into distinct blocks. These distinct blocks are called classes and a single class can contain both data (data within a class are usually referred to as attributes) and functions (functions within a class are usually referred to as methods). By organising code into unique classes, it becomes easier for a developer or programmer to identify problems and resolve them because their program is, in a sense, modular. An “object” is described as an instance of a class- this means that it has the same features defined within the class i.e. contains the same data and functions.

Abstraction

Once encapsulation is achieved, the next step is to be able to interact with the “objects” and use them without affecting the internal code contained within the original class it came from. Abstraction describes the act of making only the essential features of an object accessible but keeps the main structure hidden away.

Inheritance

Often classes can be very similar to each other and so Inheritance describes the action of bringing attributes and methods from one class to another without having to define them again. Classes that have inherited from another class can also have additional attributes and methods added to them but the inherited attributes and methods cannot be changed. The original class is usual referred to as the parent class and the inherited class is usually referred to the child class.

Polymorphism

Polymorphism is the ability for classes to have different methods defined for its purpose. Polymorphism is similar to inheritance in that it uses this same relationship between two similar classes however polymorphism has the added benefit of being able to change an already defined parent class method in the child class.

Posted in

Leave a comment