🧩

Design Patterns & LLD

Gang of Four creational, structural, and behavioral patterns; SOLID principles applied to real code; microservice-level patterns; and the machine-coding problems (Parking Lot, Elevator, Rate Limiter) that low-level design rounds actually ask.

Creational Patterns (Java)

Design Patterns

Behavioral Patterns (Java)

SOLID Principles

Q

What is the Open-Closed Principle, and what does 'open for extension, closed for modification' actually mean in practice?

intermediate

A class should be extendable to support new behavior without changing its existing, already-tested source code. In practice, this usually means depending on an abstraction (an interface) and adding new behavior by writing a NEW class that implements it, rather than adding another if/else branch to an existing class — e.g. adding a new PaymentMethod by creating a new class implementing a PaymentStrategy interface, instead of editing a giant switch statement inside PaymentProcessor.

Q

What is the Liskov Substitution Principle, and what's a classic example of violating it?

intermediate

Subtypes must be substitutable for their base type without altering the correctness of the program — anywhere a Base object is expected, a Derived object should work without surprising behavior. The classic violation is Square extending Rectangle: if setWidth() and setHeight() on Rectangle are independent, but Square must keep both equal, then a Square silently breaks any code that relies on Rectangle's contract (e.g. setting width to 5 and height to 10 and expecting area == 50).

Q

What is the Interface Segregation Principle, and why do 'fat interfaces' violate it?

intermediate

Clients shouldn't be forced to depend on methods they don't use — a class implementing an interface should need every method on it, not just some. A 'fat interface' like Worker with work() and eat() methods forces a Robot implementation to provide a meaningless eat() method; splitting it into separate Workable and Eatable interfaces lets each class implement only what actually applies to it.

Q

What is the Dependency Inversion Principle, and how does it differ from Dependency Injection?

intermediate

Dependency Inversion is a design PRINCIPLE stating that high-level modules shouldn't depend on low-level modules directly — both should depend on abstractions (interfaces). Dependency Injection is a PATTERN/TECHNIQUE for actually supplying those dependencies (typically via constructor) from the outside rather than a class creating them itself; using DI doesn't automatically guarantee DIP — you can inject a concrete class directly instead of an interface, which still violates the principle even though the dependency is technically 'injected.'

Q

What are the SOLID principles? Name all 5 with one-line definitions.

beginner

Tests whether you can rattle off SRP, OCP, LSP, ISP, and DIP cleanly under interview pressure.

Q

Single Responsibility Principle — give a bad example and refactored good example.

beginner

Tests whether you can actually spot an SRP violation in code and refactor it, not just define the principle.

Structural Patterns (Java)

OOP Fundamentals for LLD

Machine Coding Problems

Q

Design a Chess Game — pieces, moves, turn management, check/checkmate detection.

advanced

Tests whether you can model a rich rule system with polymorphic piece behavior cleanly in objects.

Q

Design a task management system like Trello — boards, lists, cards, drag-and-drop ordering.

intermediate

Tests whether you can model a nested hierarchy with ordering that needs to stay consistent as items move around.

Q

Design a Logger Framework — log levels, multiple appenders (console, file, remote).

intermediate

Tests whether you know how to design a pluggable appender architecture that's easy to extend without modifying existing code.

Q

Design a text editor with undo/redo support.

advanced

Tests whether you know the Command pattern is the natural fit for reversible, replayable operations.

Q

Design a Circuit Breaker component from scratch — CLOSED, OPEN, HALF-OPEN state machine.

advanced

Tests whether you can implement the actual state transitions and thresholds, not just describe the pattern.

Q

Design a Restaurant Reservation System — tables, time slots, party size, conflict prevention.

advanced

Tests whether you can handle overlapping-interval conflict checks and thread-safe booking cleanly.

Q

Design the classic Snake Game — grid, movement, food, collision detection, growth.

intermediate

Tests whether you can model game state and collision logic cleanly with simple data structures.

Q

Design a Concurrent HashMap from scratch — how would you implement thread-safe bucket-level locking?

expert

Tests whether you can reason about fine-grained locking design, not just use java.util.concurrent.ConcurrentHashMap as a black box.

Q

Design a Parking Lot System — multi-floor, vehicle types, fee calculation.

beginner

One of the most common machine-coding rounds — tests whether you can model entities, allocate spots, and calculate fees cleanly.

Q

Design a Vending Machine — product selection, payment, change, inventory.

beginner

Tests whether you can model a state machine (idle, selecting, paying, dispensing) cleanly in object-oriented code.

Q

Design an Elevator System — single elevator, request queue, floor movement.

intermediate

Tests whether you can design a request-scheduling algorithm and represent elevator state correctly.

Q

Design a Movie Ticket Booking System (Bookmyshow) — seats, shows, booking.

intermediate

Tests whether you can model seats, shows, and concurrent booking without double-allocating the same seat.

Q

Design a Splitwise / Expense Sharing App.

advanced

Tests whether you can model balances between multiple users and simplify debts efficiently.

Q

Design an In-Memory Rate Limiter — Token Bucket, Sliding Window algorithms.

intermediate

Tests whether you can implement at least one real rate-limiting algorithm correctly, not just name it.

Q

Design a Payment Gateway — multiple providers, retry, refund, idempotency.

advanced

Tests whether you can design around provider abstraction, safe retries, and idempotent payment processing.