Design Patterns
Gang of Four (GoF) patterns, categorised by use cases.
| # | Pattern | Category | Importance | Status | One-line Idea | Best Resources |
|---|---|---|---|---|---|---|
| 1 | OOP — 4 Pillars | Fundamentals | critical | Encapsulation, Abstraction, Inheritance, Polymorphism. Foundation of every LLD interview. | ||
| 2 | SOLID Principles | Fundamentals | critical | SRP, OCP, LSP, ISP, DIP. 5 rules for clean, maintainable, extensible OOP code. | ||
| 3 | Composition over Inheritance | Fundamentals | high | Prefer has-a over is-a. More flexible. Avoids brittle deep class hierarchies. | ||
| 4 | UML Class Diagrams | Fundamentals | high | Draw classes, interfaces, and relationships before writing a single line of code. | ||
| 5 | Interfaces vs Abstract Classes | Fundamentals | critical | Interface = contract, supports multiple. Abstract = partial implementation. Know when to use each. | ||
| 6 | Concurrency & Thread Safety | Fundamentals | high | Race conditions, deadlocks, mutex, semaphore, ReentrantLock, ThreadLocal, immutability. | ||
| 7 | Singleton | Creational | critical | One global instance. Thread-safe via enum or double-checked locking. Logger, Config, DB Pool. | ||
| 8 | Factory Method | Creational | critical | Let subclasses decide which object to create. Decouples instantiation from usage. Open/Closed. | ||
| 9 | Abstract Factory | Creational | high | Factory of factories. Create families of related objects. Cross-platform UI toolkit example. | ||
| 10 | Builder | Creational | critical | Construct complex objects step by step. Fluent API. Avoids telescoping constructor anti-pattern. | ||
| 11 | Prototype | Creational | medium | Clone existing objects instead of constructing from scratch. Shallow vs deep copy. | ||
| 12 | Object Pool | Creational | medium | Reuse a fixed set of pre-created objects. Avoids expensive construction. DB connections, threads. | ||
| 13 | Adapter | Structural | critical | Convert an incompatible interface into the expected one. Wrap legacy or third-party classes. | ||
| 14 | Decorator | Structural | critical | Add responsibilities to objects dynamically. Wrap in decorator objects. Java I/O streams. | ||
| 15 | Facade | Structural | critical | Provide a simple interface to a complex subsystem. Hide internal complexity from clients. | ||
| 16 | Proxy | Structural | high | Surrogate for another object. Lazy init, access control, logging, caching proxy. | ||
| 17 | Composite | Structural | high | Treat individual and composed objects uniformly. Tree structures. File system, UI component trees. | ||
| 18 | Bridge | Structural | medium | Decouple abstraction from implementation. Both can vary independently. Cross-platform rendering. | ||
| 19 | Flyweight | Structural | medium | Share fine-grained objects to save memory. Intrinsic (shared) vs extrinsic (per-use) state. | ||
| 20 | Observer | Behavioural | critical | Subject notifies subscribed observers when state changes. Foundation of event systems. | ||
| 21 | Strategy | Behavioural | critical | Define a family of algorithms, encapsulate each, make them interchangeable at runtime. | ||
| 22 | State | Behavioural | critical | Allow object to change behaviour when internal state changes. Finite State Machine in OOP. | ||
| 23 | Command | Behavioural | high | Encapsulate a request as an object. Enables undo/redo, queuing, logging. Text editor actions. | ||
| 24 | Template Method | Behavioural | high | Define skeleton of algorithm in base class, let subclasses fill in the steps. Hollywood Principle. | ||
| 25 | Iterator | Behavioural | high | Sequentially access elements of a collection without exposing its structure. Java Iterator. | ||
| 26 | Chain of Responsibility | Behavioural | high | Pass request along a chain of handlers. Each decides to process or pass on. Middleware, logging. | ||
| 27 | Mediator | Behavioural | medium | Centralise communication between objects. Reduces many-to-many coupling. Chat room example. | ||
| 28 | Memento | Behavioural | medium | Capture and restore object state without exposing internals. Undo functionality. | ||
| 29 | Visitor | Behavioural | medium | Add new operations to object structures without modifying them. Double dispatch. | ||
| 30 | Interpreter | Behavioural | low | Define a grammar for a language, provide an interpreter to deal with it. SQL, regex parsing. |