← Learning Design Patterns

The 22 patterns every developer should know.

Originally documented by the Gang of Four in 1994, these patterns remain the shared vocabulary of professional software design. Each one is a proven solution to a recurring problem — not a recipe to copy, but a blueprint to understand and adapt.

22Patterns
3Categories
TSExamples
GoFOrigin

What is a design pattern?

A design pattern is a general, reusable solution to a commonly occurring problem in software design. Patterns are not finished code — they're templates. Understanding them gives you a mental toolkit for recognising problems and communicating solutions with other developers using shared vocabulary like "use an Observer here" or "that's a Facade."

Structural Patterns

How to assemble objects into larger structures while keeping them flexible.

7 patterns
beginner aka: Wrapper

Adapter

Allow objects with incompatible interfaces to work together. Wrap an existing class with a new interface so legacy or third-party code fits into your system without modification.

advanced aka: Handle/Body

Bridge

Decouple abstraction from implementation so both can vary independently. Instead of a single hierarchy that explodes with every combination, Bridge uses composition to let two dimensions evolve on their own.

intermediate aka: Object Tree

Composite

Compose objects into tree structures and treat individual objects and compositions uniformly. Client code can work with a single leaf or an entire tree using the exact same interface.

intermediate aka: Wrapper

Decorator

Attach new behaviours to objects at runtime by wrapping them in decorator objects. A flexible alternative to subclassing — stack multiple wrappers to compose behaviour.

beginner

Facade

Provide a simplified interface to a complex subsystem. A Facade hides the complexity of a library, framework, or cluster of classes behind a single, easy-to-use entry point.

advanced aka: Cache

Flyweight

Share common state between many fine-grained objects to fit more into available memory. Split object state into intrinsic (shared) and extrinsic (context-dependent) parts to eliminate duplication.

intermediate aka: Surrogate

Proxy

Provide a substitute for another object. A proxy intercepts access to the real object, letting you perform actions before or after the request — caching, access control, logging, lazy loading.

Behavioral Patterns

How objects communicate and distribute responsibilities.

10 patterns
intermediate aka: CoR

Chain of Responsibility

Pass requests along a chain of handlers. Each handler decides to process the request or pass it to the next handler. Decouples senders from receivers and lets you dynamically configure the chain.

intermediate aka: Action

Command

Turn a request into a standalone object. This lets you parameterize methods with different requests, delay execution, queue operations, and implement undoable actions.

beginner aka: Cursor

Iterator

Traverse elements of a collection without exposing its underlying representation. Whether the collection is an array, tree, graph, or custom structure, the iterator provides a uniform way to walk through it.

intermediate aka: Intermediary

Mediator

Reduce direct dependencies between objects by routing all communication through a central mediator. Objects no longer talk to each other directly — they talk to the mediator, which decides what to do.

intermediate aka: Snapshot

Memento

Save and restore an object's state without violating encapsulation. The Memento pattern lets you snapshot an object's internal state so you can roll it back later — the basis of undo/redo.

beginner aka: Event Listener

Observer

Define a subscription mechanism so multiple objects are automatically notified when the object they're watching changes state. The foundation of event systems, reactive UIs, and pub/sub architectures.

intermediate aka: Objects for States

State

Let an object alter its behaviour when its internal state changes. The object appears to change its class. Instead of giant switch/if-else blocks, extract each state into its own class.

beginner aka: Policy

Strategy

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it — swap sorting, routing, pricing, or compression at runtime.

beginner

Template Method

Define the skeleton of an algorithm in a base class and let subclasses override specific steps without changing the algorithm's structure. The invariant part lives in one place; the variant parts are deferred to subclasses.

advanced

Visitor

Separate an algorithm from the object structure it operates on. Add new operations to existing class hierarchies without modifying those classes — the visitor "visits" each element and does its work.