Factory Method
Factory Method separates object creation from the workflow that uses the object, allowing a subtype or configuration to choose the concrete product.
10 patterns · Creational / Structural / Behavioral
Every pattern from Head First Design Patterns rebuilt as PROBLEM → RULE → RUN → OUTPUT, with an original TypeScript example, honest trade-offs, and the exact condition where the abstraction stops paying rent.
Creational
Factory Method separates object creation from the workflow that uses the object, allowing a subtype or configuration to choose the concrete product.
Singleton guarantees one globally reachable instance, but the convenience behaves like shared global state and must be treated as a trade-off.
Structural
Decorator wraps an object with optional layers, allowing capabilities to be combined at runtime without creating a subclass for every combination.
Adapter converts an existing interface into the interface a client expects, containing incompatibility at one explicit system boundary.
Facade offers a small task-oriented interface over a complicated subsystem, reducing the knowledge each caller needs for common workflows.
Behavioral
When one task has several valid ways to run, Strategy keeps the workflow stable while the decision-making rule can change independently.
Observer turns a state change into a broadcast so multiple dependents can react without the source knowing their concrete implementations.
Command packages a request as an object so actions can be queued, logged, retried, composed, or reversed independently from the caller.
Template Method defines a stable algorithm sequence while allowing selected steps to vary through subclass hooks or overrides.
Iterator provides a standard way to traverse a collection while hiding whether the underlying structure is an array, tree, stream, or remote page.