Skip to content

Chapter 1 of 8

The Four Pillars of OOP

Object-oriented programming rests on four foundational concepts that together shape how we model and organize software. Encapsulation is the practice of bundling data and the methods that operate on that data into a single unit, typically a class, while restricting direct access to some of the object's components. By hiding internal state and implementation details behind a controlled public interface, encapsulation protects object integrity and prevents unintended modification from outside code.

Inheritance allows a child class, or subclass, to acquire the properties and behaviors of a parent class, or superclass. In Java, declaring a Dog class with the extends keyword so that it inherits from Animal establishes a clear is-a relationship in which Dog is a specific kind of Animal. This mechanism promotes code reuse by allowing common behavior to live in a parent class, while also enabling polymorphic behavior when subclasses provide their own specialized implementations.

Polymorphism, literally meaning "many forms," is the ability of an object to take on different behaviors depending on its actual type. It comes in two main forms: compile-time polymorphism achieved through method overloading, where the compiler picks the right method based on argument types, and run-time polymorphism achieved through method overriding, where the call is resolved at runtime based on the object's actual class. A draw method on a Shape, for instance, will render a Circle differently from a Rectangle even when invoked through a common Shape reference.

Abstraction focuses on hiding complex implementation details and exposing only the essential features of an object. In practice, this is achieved through abstract classes that provide partial implementations, and through interfaces that define a pure contract with no implementation at all. A Vehicle interface, for example, might expose only start and stop methods, deliberately concealing the intricacies of how engines actually work.

All chapters
  1. 1The Four Pillars of OOP
  2. 2The SOLID Design Principles
  3. 3Classes, Objects, and Language Mechanics
  4. 4Object Relationships
  5. 5Polymorphism and Method Dispatch
  6. 6Abstraction Through Interfaces and Abstract Classes
  7. 7Composition, Inheritance, and Code Reuse
  8. 8General Software Design Principles

Drill it

Reading is not remembering. These come from the Oop Principles deck:

Q

What is encapsulation in OOP?

Encapsulation is the bundling of data and methods that operate on that data into a single unit (class), while restricting direct access to some components.Key b...

Q

What is inheritance in OOP?

Inheritance allows a child class (subclass) to acquire the properties and behaviors of a parent class (superclass).Example in Java:class Dog extends Animal { }B...

Q

What is polymorphism in OOP?

Polymorphism means "many forms" — the ability of an object to take on different behaviors depending on its type.Two main types:Compile-time (static): method ove...

Q

What is abstraction in OOP?

Abstraction is the process of hiding complex implementation details and exposing only the essential features of an object.Achieved through:Abstract classes — pa...