The Three Pillars of Object-Orientation

Owen Schacherer
Mar 11, 2024

Introduction

There are three pillars of object-orientation that ensure the development of modular, maintainable, and extensible systems. These pillars include inheritance, encapsulation, and polymorphism. The three pillars of object-orientation are concepts that guide the design and definition of systems and languages that use objects and their interactions to solve problems.

Before diving into the pillars themselves, some background should build the necessary picture of what object-oriented systems are and what they are made of.

What is a Class?

A class is an abstraction that defines the properties and behaviors of certain real entities. An example is the “Car” class. The “Car” class might include certain properties like color, make, and model. It could have behaviors like lock doors, start engine, and many more. Classes are distinct from real entities; these are known as objects.

What is an Object?

An object is an instance of a class. These real entities represent unique things. Going back to the “Car” class example, one of its objects could be a red Toyota Camry. This instance would have certain properties defined with values and all the behaviors of the class. Objects set the stage for object-oriented programming.

What is Object-Oriented Programming?

Object-oriented programming (OOP) is a high-level programming paradigm that is instantiated by certain languages for the implementation of object-oriented software solutions. Some examples of OOP languages are Java, C++, C#, and many others. Each of these languages attempts to ensure the three pillars of object-orientation.

Pillar One: Encapsulation

Encapsulation is the bundling of data and the methods that mutate or access it. This can be easily accomplished with classes, as long as they are used properly. By preventing the unnecessary exposure of internal code, a separation of concerns is established between one encapsulated unit and another external unit. Encapsulation is only one piece of an object-oriented approach.

Pillar Two: Inheritance

Inheritance is a definition tool that allows one object to be based on one or more other objects. A class that inherits another is known as a subclass. A subclass inherits the features of its superclass. Inheritance allows for the reuse of code, clean organization, and extensibility. Take the “Car” class for instance again; a Car is really an automobile and therefore “Automobile” is its superclass and “Car” is a subsequent subclass. With this new family tree of classes, an opportunity presents itself, Polymorphism.

Pillar Three: Polymorphism

Polymorphism is the ability to use objects from different classes the same way as their common superclass. This capability allows for the reduction of code and complexity via flexibility and extensibility, i.e. a process defined for “Automobiles” can be applied to “Cars” and “Trucks”, saving much time.

Conclusion

The pillars of object-orientation are encapsulation, inheritance, and polymorphism. They must be carefully applied to maintain their power and utility. They allow for solutions that are easy to visualize and take less work to build, maintain, and extend. Without keeping these pillars in mind while using an OOP language, you will miss out on benefits and be working against the intentional grain set out by its creators.

About the author

Software Consultant | USA
I am a Software engineering consultant within Sogeti with a passion for innovation, growth, object-oriented design, and artificial intelligence/machine learning. I obtained a B.S. in Software Engineering at Iowa State University in 2021, during which I took two AI/ML classes and my senior design protected centered around Object Detection.

    Leave a Reply

    Your email address will not be published. Required fields are marked *