Design Patterns
Design Patterns
Gang of Four patterns split into creational, structural, and behavioral.
1 min readDesigns · LLD & Patterns
22 patterns from the Gang of Four book, organized by intent.
Creational
Object creation: Singleton, Factory, Abstract Factory, Builder, Prototype
Structural
Class composition: Adapter, Decorator, Facade, Proxy, Composite, Bridge, Flyweight
Behavioral
Object interaction: Strategy, Observer, Command, State, Chain of Responsibility, Template Method, Iterator, Mediator, Visitor, Memento
Picking the Right Pattern
| Symptom | Reach for |
|---|---|
if/else cascade selecting an algorithm | Strategy |
| Many optional constructor parameters | Builder |
| Need exactly one shared instance | Singleton |
| Object behavior changes with internal state | State |
| Adding cross-cutting features (logging, retry, cache) | Decorator |
| Bridging incompatible interfaces | Adapter |
| Tree of nested objects, treat them uniformly | Composite |
| Notify many dependents of a state change | Observer |
| Undo/redo, queue, replay | Command |
| Hide a complex subsystem | Facade |
| Family of related objects (UI theme, DB driver) | Abstract Factory |
| Two orthogonal axes of variation | Bridge |
| Millions of similar objects, save memory | Flyweight |
| Multiple handlers for one request | Chain of Responsibility |
| Skeleton algorithm with overridable steps | Template Method |
Finished reading?
Mark it done to track your progress in Designs.