Design Patterns
The 22 GoF patterns that show up in LLD interviews — each tied to the problem it solves, with Java.
Design patterns are solutions to recurring design problems — they exist because a production problem burned someone first. Learn the intent and the trade-off, not the diagram.
Interview rule: you must be able to say which concrete LLD problem each pattern solves (e.g. State → vending machine, Strategy → pricing), and you must read the GoF names fluently.
Creational
Creational 1 — Factory
CreationalCentralize object creation behind one method so callers depend on the created type's contract, not its construction logic.
7 min 1 code practice
Creational 2 — Abstract Factory
CreationalProvides an interface for creating a family of related objects without specifying their concrete classes — e.g. a UI kit that produces LightButton + LightDialog together.
6 min 1 code practice
Creational 3 — Builder
CreationalConstruct complex objects step-by-step with readable, fluent calls — especially when there are many optional or immutable fields.
7 min 1 code practice
Creational 4 — Prototype
CreationalClone an existing instance instead of re-running expensive construction. Rare in interviews — know the intent, not the ceremony.
7 min 1 code practice
Creational 5 — Singleton
CreationalOne instance per JVM, with a globally reachable accessor. Interviews love it because naive implementations break under concurrency.
7 min 1 code practice
Structural
Structural 1 — Adapter
StructuralMake an incompatible interface look like the one your client expects — a translator between contracts.
6 min 1 code practice
Structural 2 — Decorator
StructuralWrap an object to add behavior at runtime, stackable without touching the original class.
6 min 1 code practice
Structural 3 — Facade
StructuralOne simplified entry point that hides a messy subsystem of many classes.
7 min 1 code practice
Structural 4 — Proxy
StructuralA stand-in that controls access to the real object: lazy init, access control, caching, remote calls.
7 min 1 code practice
Structural 5 — Composite
StructuralTreat individual objects and groups of objects uniformly — a tree where leaves and nodes share an interface.
6 min 1 code practice
Structural 6 — Bridge
StructuralDecouple an abstraction from its implementation so both can vary independently — avoids the 2D class explosion.
7 min 1 code practice
Structural 7 — Flyweight
StructuralShare the intrinsic (immutable, common) part of many fine-grained objects and pass the extrinsic (per-use) part in, so a million objects cost the memory of a few hundred.
7 min 1 code practice
Behavioral
Behavioral 1 — Strategy
BehavioralEncapsulate a family of algorithms behind one interface and swap them at runtime — the single most used pattern in LLD interviews.
8 min 1 code practice
Behavioral 2 — Observer
BehavioralOne subject notifies many listeners when its state changes — the publish/subscribe idea in-process.
7 min 1 code practice
Behavioral 3 — Command
BehavioralWrap a request (and its receiver) into an object — enables undo/redo, queuing, logging, and macros.
7 min 1 code practice
Behavioral 4 — State
BehavioralAn object changes behavior when its state changes — state logic moves from if/else soup into per-state classes. The vending machine pattern.
8 min 1 code practice
Behavioral 5 — Template Method
BehavioralDefine the skeleton of an algorithm in a base class, let subclasses fill in specific steps — inversion of control inside one class hierarchy.
6 min 1 code practice
Behavioral 6 — Chain of Responsibility
BehavioralPass a request along a chain of handlers; each handler decides to process it or pass it on. Middleware, filters, validators.
6 min 1 code practice
Behavioral 7 — Iterator
BehavioralProvide sequential access over a collection without exposing its internals. Mostly baked into Java today — nested iterators (tree walks, pagination) still show up.
6 min 1 code practice
Behavioral 8 — Mediator
BehavioralCentralize interactions between many objects so they talk to one mediator instead of each other — star topology.
7 min 1 code practice
Behavioral 9 — Memento
BehavioralSave a snapshot of an object's state so you can restore it later, without exposing its private fields. Think 'save game' in a video game.
7 min 1 code practice
Behavioral 10 — Visitor
BehavioralAdd new operations to a group of classes without changing those classes. The operation 'visits' each object and does the right thing for its type.
7 min 1 code practice