System Design ( Day - 42 )

Manoj KumarManoj Kumar
2 min read

OOP & UML Revision: From Machine Code to Modeling

1. OOP Evolution: Why We Needed Objects

  1. Machine Language (0s & 1s):

    • Tedious, error-prone, unscalable.
  2. Assembly Language:

    • Mnemonics replace bits, but still low-level & brittle.
  3. Procedural Programming:

    • Functions, loops, blocks—but no real-world modeling, limited reuse.
  4. Object-Oriented Programming (OOP):

    • Models real-world entities as objects with state (variables) and behavior (methods).

    • Boosts data security, scalability, and reusability.


2. Four Pillars of OOP

  1. Abstraction 🕹️

    • Hide complexity: Use a TV remote without knowing its circuits.

    • In code: Expose only necessary methods; hide implementation details.

  2. Encapsulation 🔐

    • Bundle data & behavior: A Class is a blueprint; access modifiers (public, private, protected) guard internal state.

    • Protect invariants: Prevent outside code from corrupting your object’s state.

  3. Inheritance 🚗

    • Reuse common features: CarManualCar & AutomaticCar inherit start(), stop(), accelerate().

    • “is-a” relationship: Child classes extend parent capabilities without duplication.

  4. Polymorphism 🦆🐯

    • Runtime (Overriding): run() behaves differently for Duck, Tiger, Human.

    • Compile-time (Overloading): run() vs run(speed) in Human—same method name, different signatures.


3. UML Diagrams: Visualizing Structure & Behavior

UML is the lingua franca for system design. Two essentials:

A. Class Diagrams (Static Structure)

  • Classes & Attributes

  • Associations:

    • Inheritance (is-a): Parent —▷ Child

    • Simple (uses-a): A —> B

    • Aggregation (has-a, loose): A —<> B

    • Composition (has-a, tight): A —◇ B

B. Sequence Diagrams (Dynamic Behavior)

  • Lifelines: Object lifespans

  • Activation Bars: When an object is active

  • Messages:

    • Synchronous (→) vs Asynchronous (–>)
  • Special Messages: Create, Destroy, Lost, Found

Example: ATM Withdrawal

  1. User inserts card → ATM

  2. ATM verifies PIN → Transaction

  3. Transaction checks Account → CashDispenser

  4. CashDispenser dispenses cash → User

0
Subscribe to my newsletter

Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Manoj Kumar
Manoj Kumar