Design Patterns for LLD
Learn the creational, structural and behavioural patterns that show up most in LLD rounds, and when each one genuinely helps.
Intermediate · about 6 hours · difficulty 3/5
Learn first: OOP Principles and SOLID
Design patterns are named, reusable solutions to recurring design problems. In LLD interviews, using the right pattern (and naming it) shows maturity; forcing patterns everywhere shows the opposite.
Creational
- Singleton: one shared instance (a config or a parking lot instance). Easy to overuse; it hides dependencies and complicates tests.
- Factory / Factory Method: create objects without the caller knowing the concrete class (VehicleFactory.create("CAR")).
- Builder: construct complex objects step by step (an Order with many optional fields).
Structural
- Adapter: wrap an incompatible interface (Razorpay and PayU SDKs behind one PaymentGateway).
- Decorator: add behaviour by wrapping (a pizza with toppings, a logging or caching wrapper around a repository).
- Facade: one simple interface over a complex subsystem.
- Proxy: control access (lazy loading, caching, auth checks).
Behavioural
- Strategy: swap algorithms at runtime (pricing, parking fee calculation, split types in Splitwise). The most useful pattern in LLD rounds.
- Observer: notify subscribers on change (seat availability updates, notification services).
- State: behaviour depends on state (a vending machine: Idle, HasMoney, Dispensing; an order: Placed, Preparing, Delivered).
- Command: wrap a request as an object (undo, queues).
- Chain of Responsibility: pass a request along handlers (ATM cash dispensing by note denomination, middleware).
- Template Method and Iterator round out the common set.
Pitfalls
- Reciting patterns without explaining the problem they solve in this design.
- Singleton for everything, making code untestable and thread-unsafe.
- Confusing Strategy and State: Strategy is chosen by the client; State transitions itself.
You are ready to move on when you can pick and justify a pattern for vending machine states, multiple payment providers and different fare calculation rules.
Key concepts
- Singleton
- Factory and Builder
- Adapter, Decorator, Facade
- Strategy
- Observer
- State
- Command and Chain of Responsibility
- Proxy and Template Method
Mini project
Implement a vending machine using the State pattern, an Observer-based low-stock alert, and a Strategy for payment (cash, UPI, card). Write a short README naming each pattern and the problem it solves.
Check yourself
What is the difference between the Strategy and State patterns, given that their class diagrams look almost the same?
Free resources
- Design patterns catalog (Refactoring.Guru)
- Awesome Low Level Design (GitHub)
- Java design patterns (java-design-patterns.com)