# Design Patterns for LLD

> Learn the creational, structural and behavioural patterns that show up most in LLD rounds, and when each one genuinely helps. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/system-design/design-patterns
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/system-design/oop-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](https://refactoring.guru/design-patterns) (Refactoring.Guru)
- [Awesome Low Level Design](https://github.com/ashishps1/awesome-low-level-design) (GitHub)
- [Java design patterns](https://java-design-patterns.com/) (java-design-patterns.com)

Previous: [OOP Principles and SOLID](https://www.internhack.in/roadmaps/tracks/system-design/oop-and-solid) · Next: [Approaching an LLD Problem: Requirements, Entities and UML](https://www.internhack.in/roadmaps/tracks/system-design/lld-approach-and-uml)

## More in Low-Level Design (LLD) and Object-Oriented Design

- [OOP Principles and SOLID](https://www.internhack.in/roadmaps/tracks/system-design/oop-and-solid)
- [Design Patterns for LLD](https://www.internhack.in/roadmaps/tracks/system-design/design-patterns)
- [Approaching an LLD Problem: Requirements, Entities and UML](https://www.internhack.in/roadmaps/tracks/system-design/lld-approach-and-uml)
- [LLD Case Study: Parking Lot](https://www.internhack.in/roadmaps/tracks/system-design/lld-parking-lot)
- [LLD Case Study: Movie Ticket Booking (BookMyShow)](https://www.internhack.in/roadmaps/tracks/system-design/lld-bookmyshow)
- [LLD Case Study: Expense Sharing (Splitwise)](https://www.internhack.in/roadmaps/tracks/system-design/lld-splitwise)
- [The Machine Coding Round](https://www.internhack.in/roadmaps/tracks/system-design/machine-coding-round)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [System Design Roadmap](https://www.internhack.in/roadmaps/tracks/system-design)
