Quick Reference
One-page per pattern. Print-friendly.
WHICH PATTERN? DECISION FLOWCHART
Need to CREATE objects? → How many types?
One type, complex build → Builder
Multiple types, same interface → Factory Method
Families of related types → Abstract Factory
Only one instance → Singleton (or DI scope)
Need to STRUCTURE relationships?
Make incompatible interfaces work → Adapter
Simplify a complex subsystem → Facade
Add behavior without modifying → Decorator
Control access to an object → Proxy
Part-whole tree → Composite
Need to manage BEHAVIOR?
Swap algorithms → Strategy
Object changes behavior based on state → State
Notify many listeners → Observer
Pipeline of handlers → Chain of Responsibility
Queue, undo, log actions → Command
Same skeleton, different steps → Template Method
No pattern fits? A function or a simple class is fine. Do not force it.
Factory Method
CreationalCreator → Product ConcreteCreator → ConcreteProduct
abstract createProduct(): Product
Strategy
BehavioralContext → Strategy ConcreteStrategyA, ConcreteStrategyB
ctx.setStrategy(new ConcreteStrategy()) ctx.execute()
Observer
BehavioralSubject → Observer[] ConcreteObserverA, ConcreteObserverB
subject.subscribe(observer) subject.notify()
Decorator
StructuralComponent → ConcreteComponent Decorator → Component (wraps)
new LoggingDecorator(new RateLimiter(handler))
State
BehavioralContext → State ConcreteStateA, ConcreteStateB
this.state = new PaidState() this.state.handle()
Builder
CreationalDirector → Builder ConcreteBuilder → Product
new Builder().setX(a).setY(b).build()
Adapter
StructuralClient → Target Adapter → Adaptee
class StripeAdapter implements PaymentGateway { ... }Facade
StructuralFacade → SubsystemA, SubsystemB, SubsystemC
orderFacade.placeOrder(cart, payment, shipping)
Command
BehavioralInvoker → Command ConcreteCommand → Receiver
cmd.execute(); history.push(cmd); cmd.undo()
Chain of Responsibility
BehavioralHandler → Handler (next) ConcreteHandlerA, ConcreteHandlerB
handler.setNext(auth).setNext(validate).setNext(process)
Proxy
StructuralClient → Subject Proxy → RealSubject
class CachingProxy implements Repository { ... }Singleton
CreationalSingleton (private constructor, static instance)
class DB { static instance: DB; static get() { ... } }Abstract Factory
CreationalAbstractFactory → ProductA, ProductB ConcreteFactory1, ConcreteFactory2
factory.createRepo(); factory.createMigration()
Template Method
BehavioralAbstractClass (templateMethod, step1, step2) ConcreteClass overrides steps
abstract class Report { generate() { fetch(); validate(); render(); } }Composite
StructuralComponent → Leaf, Composite Composite contains Component[]
group.getPrice() // sums children recursively
Mediator
BehavioralMediator → Colleague[] Colleague → Mediator
chatRoom.send(userId, message, targetId)
Bridge
StructuralAbstraction → Implementation RefinedAbstraction, ConcreteImplementation
new AlertNotification(new EmailChannel())
Dependency Injection
ExtraClient → Interface ← Implementation Container wires them
constructor(private readonly repo: UserRepository) {}Repository
ExtraService → Repository (interface) TypeORMRepository, PrismaRepository
interface UserRepo { findById(id): User; save(user): void }Event Bus / Pub-Sub
ExtraPublisher → Broker → Subscriber[] Topics route messages
eventBus.publish('order.placed', order)
eventBus.subscribe('order.placed', handler)Circuit Breaker
ExtraClosed → Open → HalfOpen Trips after N failures
const breaker = new CircuitBreaker(apiCall, { threshold: 5 })