← Back to Low-Level Design

Low-Level Design — Quick Summary

Quick revision: every topic, key terms, and mnemonics for Low-Level Design.


This is a quick revision doc covering all 33 topics in lld. Open the linked notes if you want depth.

Foundations

What is Low-Level Design?

What it is. Designing the code structure of a system — classes, interfaces, methods, relationships. The blueprint for how we’d actually write code.

Key terms.

Remember. Interviewers want: requirement gathering, class identification with right responsibilities, relationships, design patterns, extensibility, clean code. Red flag = god class doing everything.

OOP: The Four Pillars

What it is. Encapsulation, Abstraction, Inheritance, Polymorphism.

Key terms.

Remember. Encapsulation hides data; abstraction hides complexity. Polymorphism is what makes for shape in shapes: shape.area() work without knowing types.

Composition vs Inheritance

What it is. Two ways to reuse behavior. Favor composition over inheritance.

Key terms.

Remember. Start with composition. Reach for inheritance only when “is-a” is obvious and depth ≤ 3 levels. Composition lets us mix abilities (FightAbility + FlyAbility + MagicAbility) without explosion.

Abstract Classes vs Interfaces

What it is. Two ways to define contracts.

Key terms.

Remember. Dog extends Animal (abstract — IS an animal). Dog implements Trainable (interface — CAN be trained). Most patterns (Strategy, Observer, Factory) use interfaces.

SOLID Principles

Cheatsheet — SOLID

LetterPrincipleOne-line
SSingle ResponsibilityOne class, one reason to change
OOpen/ClosedOpen for extension, closed for modification
LLiskov SubstitutionSubclasses must be substitutable for parents
IInterface SegregationNo class forced to implement methods it doesn’t use
DDependency InversionDepend on abstractions, not concretes

Remember. SOLID = SRP / OCP / LSP / ISP / DIP. Each principle solves a different smell — SRP fights god classes, OCP fights if-else explosions, LSP fights surprising overrides, ISP fights fat interfaces, DIP fights tight coupling.

Single Responsibility Principle (SRP)

What it is. A class should have one reason to change.

Red flags. Class name has “And” or “Manager.” Methods don’t use each other. Class grows past ~500 lines. Unrelated changes touch the same class.

Remember. SRP isn’t “one method per class.” UserService with create/update/delete/find is fine — all manage user data. The question: how many reasons to change? UserManager doing user creation + email sending + logging = 3 reasons = split it.

Open/Closed Principle (OCP)

What it is. Open for extension, closed for modification.

Key terms.

Remember. Adding a new payment type should mean adding a class, not modifying existing code. The OCP recipe: abstraction → implementations → depend on abstraction.

Liskov Substitution Principle (LSP)

What it is. If B extends A, anywhere we use A we should be able to use B without surprises.

Red flags.

Remember. Classic violation: Square extends Rectangle. The fix: don’t force the inheritance — make both implement Shape interface. Subclasses strengthen parent promises, never weaken.

Interface Segregation Principle (ISP)

What it is. No class should be forced to implement methods it doesn’t use.

Red flags.

Remember. RobotWorker forced to implement eat() and sleep() is the textbook violation. Split fat interfaces (Worker) into small focused ones (Workable, Eatable, Sleepable). Each class implements only what it needs.

Dependency Inversion Principle (DIP)

What it is. Depend on abstractions, not concretes. Inject dependencies from outside.

Key terms.

Remember. NotificationService shouldn’t new EmailSender() itself — accept a MessageSender interface in the constructor. Now we can swap Email/SMS/Slack/MockSender. DIP is what makes everything else testable.

Design Principles

DRY, KISS, and YAGNI

Key terms.

Remember. Cost of YAGNI violations: time, complexity, bugs, maintenance for nobody. In LLD interviews: don’t add interfaces and abstractions until there’s a real reason.

Coupling and Cohesion

What it is. Quality metrics for design.

Key terms.

Quick gut checks.

Remember. Low coupling, high cohesion is the result of following SOLID. SRP → cohesion. DIP → less coupling. ISP → cohesive interfaces. OCP → less concrete coupling.

UML Class Diagrams

What it is. Visual sketch language for class relationships.

Key terms.

Remember. Speed > perfection. Boxes first, arrows later. Talk while drawing. Composition for “owns lifecycle.” Aggregation for “has, independent.”

Creational Design Patterns

Singleton Pattern

What it is. Only one instance of a class, with global access.

Key terms.

Remember. Use for DB pools, loggers, configs, caches. Beware — singletons = global state = hard to test. Don’t use just because we can.

Factory Pattern

What it is. Centralize object creation. Two flavors:

Remember. Replaces if-else for type-based instantiation. Factory Method = one product type. Abstract Factory = family of matching products. Eliminates “new ConcreteClass()” everywhere.

Builder Pattern

What it is. Build complex objects step by step. Fluent chaining.

Key terms.

Remember. Use for 4+ optional parameters. Pizza.builder().size("large").addCheese().addPepperoni().build(). Below 3-4 params, just use a constructor.

Prototype Pattern

What it is. Create new objects by cloning existing ones.

Key terms.

Remember. Use when construction is expensive (DB query, file I/O) or when copying without knowing concrete class. Always deep-copy if there are nested objects.

Structural Design Patterns

Adapter Pattern

What it is. Wrap an incompatible class to match the interface our code expects.

Key terms.

Remember. Use for third-party libraries with different signatures or legacy code. Adapter is a translator — neither side changes, the middleman handles translation.

Decorator Pattern

What it is. Add behavior to objects by wrapping them. Stack layers like LEGO.

Key terms.

Remember. Coffee + Milk + Sugar + WhippedCream — each is a decorator wrapping the previous. Real-world: Java I/O streams, Express middleware. Decorator enhances the wrapped object.

Facade Pattern

What it is. Simple interface in front of complex subsystem.

Key terms.

Remember. “Restaurant waiter coordinating chef + dishwasher + sommelier.” Real-world: jQuery, ORMs, AWS SDK, Express. Facade simplifies; Adapter translates; Proxy controls access.

Proxy Pattern

What it is. Surrogate that controls access to the real object. Same interface.

Key terms.

Remember. Proxy controls. Decorator enhances. Adapter translates. Use for lazy loading, access control, caching, logging, remote access.

Behavioral Design Patterns

Observer Pattern

What it is. One-to-many: subject changes → all observers notified automatically.

Key terms.

Remember. YouTube subscriptions analogy. Use for events, real-time UI, notifications, data binding (React/MobX). Always unsubscribe to avoid memory leaks.

Strategy Pattern

What it is. Family of interchangeable algorithms. Pick one at runtime.

Key terms.

Remember. Payment methods, discount calculators, sorting algorithms, navigation routes. Strategy = client picks the algorithm.

State vs Strategy (interview favorite)

StateStrategy
Who switches?States transition themselvesClient picks
States know each other?YesNo
PurposeObject lifecycleAlgorithm swap
ExampleOrder: Placed → Shipped → DeliveredPayment: Card / PayPal / Crypto

Command Pattern

What it is. Encapsulate a request as an object with execute() and undo().

Key terms.

Remember. Restaurant order slip analogy. Editor undo/redo is the canonical example. To undo: keep history stack. To redo: keep redo stack. Implementing transactions: execute commands; on failure, run undo() in reverse.

State Pattern

What it is. Object’s behavior changes based on internal state. Each state is its own class.

Key terms.

Remember. Vending machine: Idle → HasMoney → Dispensing. ATM: Idle → Auth → Menu. Each state controls what’s allowed. New state? New class, no existing code touched.

Template Method Pattern

What it is. Define algorithm skeleton in base class; subclasses override specific steps.

Key terms.

Remember. Data processing pipelines, game loops, web framework hooks. The flow is fixed; only specific steps vary. ETL: read → parse (varies) → validate → output.

Cheatsheet — Pattern Categories

CategoryPatternsWhat they do
CreationalSingleton, Factory, Builder, PrototypeObject creation
StructuralAdapter, Decorator, Facade, ProxyClass composition
BehavioralObserver, Strategy, Command, State, TemplateObject collaboration

Real LLD Questions

Design a Parking Lot

Core entities. ParkingLot (Singleton) → Floors → ParkingSpots. Vehicle (Car/Bike/Truck). Ticket. PricingStrategy.

Key concepts.

Remember. Composition: ParkingLot has Floors, Floor has Spots. Don’t make a ParkingLotManager that does everything. Pricing pluggable = OCP. Extensions: valet, EV charging, reserved spots, multiple gates, dynamic pricing.

Design an Elevator System

Core entities. ElevatorSystem → Elevators + SchedulingStrategy. Each Elevator has Door, Display, Direction, up/down request sets.

Key concepts.

Remember. Use a TreeSet/sorted structure for up/down requests for O(log n) min/max. The hardest part is the scheduling decision — Strategy pattern fits perfectly. Extensions: priority floors, emergency mode, weight limit, zone scheduling, VIP elevator.

Design BookMyShow

Core entities. Movie, Theater, Screen, Show, Seat, Booking, Payment. Show ties Movie + Screen + StartTime.

Key concepts (the seat-locking problem is the heart).

Remember. Without locking, two users can book the same seat. Use pessimistic locking with TTL. SeatPrice depends on SeatType (REGULAR/PREMIUM/VIP). Extensions: coupons (Strategy), food orders, refund policy (Strategy), waitlist (Observer), dynamic pricing.

Design a Vending Machine

Core entities. VendingMachine (context) + State (Idle/HasMoney/Dispensing) + Inventory + Product.

Key concepts.

Remember. Without State pattern, every method is a giant if state == X chain. Each state class handles what’s valid in that state. Extensions: card payment, admin refill, multiple-product cart, denomination handling, display.

Design Snake & Ladder

Core entities. Game → Board + Players + Dice. Board has Snakes + Ladders.

Key concepts.

Remember. Each class one job: Dice rolls, Board calculates positions, Player tracks state, Game manages turns. Snakes use Map (head→tail), Ladders use Map (bottom→top). Extensions: multiple dice, special cells (power-ups), save/resume (Memento), chained snakes/ladders.

Design Chess

Core entities. Game → Board + Players. Board has 8x8 grid of Pieces. Six piece types: King/Queen/Rook/Bishop/Knight/Pawn.

Key concepts.

Remember. findKing(color) and isUnderAttack(row, col, byColor) are the helpers for check detection. After moving, if our king is attacked, undo. Adding new piece type = new class, no other changes. Extensions: castling (track hasMoved), en passant (track lastMove), pawn promotion, undo (Command), checkmate detection (try all moves).

Design Library Management

Core entities. Library → Books + Members. Book has many BookItems. Member has many Loans.

Key concepts.

Remember. Library acts as Facade. Borrow flow: find member → check limit → find available item → mark LOANED → create Loan. Return: calc fine → AVAILABLE → notify waitlist. Extensions: renewal, member tiers (Strategy), digital books, multi-criteria search (Builder).

Design ATM

Core entities. ATM (context) + ATMState (Idle/Auth/Menu/Transaction) + CashDispenser + Card + Account + Transaction.

Key concepts.

Remember. Same buttons mean different things per state. State is THE pattern here. Cash dispenser tracks physical cash; reject if low. Extensions: multi-currency (denomination strategy), receipt printer (Observer), admin mode (new state), hardware failure recovery (Command rollback).