System Design ( Day - 42 )

OOP & UML Revision: From Machine Code to Modeling
1. OOP Evolution: Why We Needed Objects
Machine Language (0s & 1s):
- Tedious, error-prone, unscalable.
Assembly Language:
- Mnemonics replace bits, but still low-level & brittle.
Procedural Programming:
- Functions, loops, blocks—but no real-world modeling, limited reuse.
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
Abstraction 🕹️
Hide complexity: Use a TV remote without knowing its circuits.
In code: Expose only necessary methods; hide implementation details.
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.
Inheritance 🚗
Reuse common features:
Car
→ManualCar
&AutomaticCar
inheritstart()
,stop()
,accelerate()
.“is-a” relationship: Child classes extend parent capabilities without duplication.
Polymorphism 🦆🐯
Runtime (Overriding):
run()
behaves differently forDuck
,Tiger
,Human
.Compile-time (Overloading):
run()
vsrun(speed)
inHuman
—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
User inserts card → ATM
ATM verifies PIN → Transaction
Transaction checks Account → CashDispenser
CashDispenser dispenses cash → User
Subscribe to my newsletter
Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
