logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
60-Day LLD & Machine Coding Mastery Roadmap
The Four Pillars of OOPComposition, Asociation & AggregationDatabase locking / atomic updates
Don't Repeat Yourself (DRY) PrincipleKeep it Simple, Stupid (KISS) PrincipleYou Aren't Gonna Need It (YAGNI) Principle
Design a Library Management System (LMS)Design a Parking LotVending Machine
D : Dependency InversionI : The Interface Segregation PrincipleL : The Liskov Substitution PrincipleO : The Open/Closed PrincipleS : The Single Responsibility Principle
UML Activity Diagrams: Modeling Process and WorkflowUML Class Diagrams: Static Structure ModelingUML Sequence Diagrams: Modeling Dynamic InteractionsUse Case Diagrams: Functional Requirement Modeling
Low Level Design

The Four Pillars of OOP

3 min read
On this pageI. Encapsulation (Data Hiding) : protect valid state
I. Encapsulation (Data Hiding) : protect valid stateII. Abstraction : expose what callers needIII. InheritanceIV. PolymorphismOOAD: Object-Oriented Analysis and Design

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects," which can contain data (attributes/properties) and code (methods/functions). Instead of focusing on logic and functions, OOP focuses on the data objects that developers want to manipulate.

Click to expand tip
  • A Class is a blueprint, prototype, or template that defines the variables and the methods common to all objects of a certain kind. It exists only in the source code; it does not occupy memory at runtime until it is instantiated.
  • An Object is a self-contained unit of a system, an instance of a class. It represents a real-world entity (e.g., a specific "User" or a "Bank Account") and holds its own unique state.

To be considered truly object-oriented, a language or design must implement these four principles:

# I. Encapsulation (Data Hiding) : protect valid state

Encapsulation is the bundling of data and the methods that act on that data into a single unit (the class). It restricts direct access to some of an object's components, which is a vital way to prevent accidental state corruption.

  • Mechanism: Achieved using Access Modifiers:
    • Private: Accessible only within the class.
    • Protected: Accessible within the class and its subclasses.
    • Public: Accessible from anywhere.
  • Benefit: The internal "how-to" is hidden; users interact only through a public interface (Getters/Setters).

Encapsulation asks: Who is allowed to change this state, and how do we keep it valid?

# II. Abstraction : expose what callers need

Abstraction is the process of hiding the complex implementation details and showing only the necessary features of an object. It reduces complexity by letting the programmer focus on what an object does instead of how it does it.

  • Mechanism: Achieved through Interfaces and Abstract Classes.
  • Analogy: You know that pressing the accelerator makes the car go faster, but you don't need to understand the internal combustion process to drive.

Abstraction asks: What does a caller need to know, and what implementation details can remain hidden?

# III. Inheritance

Inheritance is a mechanism where a new class (Subclass/Derived) acquires the properties and behaviors of an existing class (Superclass/Base).

  • Relationship: It models an "Is-A" relationship (e.g., a "Dog" is a "Mammal").
  • Benefit: Promotes Code Reusability.
  • Modern Note: Favor Composition over Inheritance where possible to avoid rigid, deep hierarchies.

Inheritance is appropriate when a subtype genuinely satisfies the contract of its parent.

# IV. Polymorphism

Polymorphism (meaning "many forms") allows objects of different classes to be treated as objects of a common superclass.

  • Static (Compile-time) Polymorphism: Method Overloading (same method name, different parameters).
  • Dynamic (Runtime) Polymorphism: Method Overriding (a subclass provides a specific implementation of a method already defined in its parent).

# OOAD: Object-Oriented Analysis and Design

The process of building a system involves identifying objects and mapping their interactions:

  1. Identify Objects: Determine the entities within the system domain.
  2. Define Relationships: Determine how objects interact (Inheritance, Composition, etc.).
  3. Establish Interfaces: Define the public methods/contracts for each object.
  4. Implementation: Convert the design into executable code using an OO language (Java, C++, Python, C#, etc.).
←Previous60-Day LLD & Machine Coding Mastery RoadmapNext→Composition, Asociation & Aggregation

On this page

I. Encapsulation (Data Hiding) : protect valid stateII. Abstraction : expose what callers needIII. InheritanceIV. PolymorphismOOAD: Object-Oriented Analysis and Design