The Three Families of GoF Patterns
Design patterns are proven recipes for recurring software design problems. This guide groups the classic GoF patterns into three families.
Creational Patterns
Control object creation: Singleton, Factory Method, Abstract Factory, Builder, Prototype.
// Builder pattern in TypeScript
class QueryBuilder {
private query = { select: "*", where: "", limit: 10 };
where(condition: string) { this.query.where = condition; return this; }
limit(n: number) { this.query.limit = n; return this; }
build() { return this.query; }
}
Structural Patterns
Compose objects and classes: Adapter, Decorator, Proxy, Facade, Bridge, Composite, Flyweight.
Behavioural Patterns
Define communication between objects: Observer, Strategy, Command, Chain of Responsibility, Iterator, State, Template Method, Visitor, Mediator, Memento, Interpreter.
Each pattern is illustrated with a minimal TypeScript snippet and a clear "when to use" note, making this the ideal desk reference for code reviews and system design interviews.
