Design Patterns

The 23 canonical Gang of Four design patterns — Creational, Structural, Behavioral.

Source: Gamma, Helm, Johnson, Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley, 1994). Code examples on this sub-site are illustrative adaptations written for the site, not direct quotations from the book.

A factory interface that produces a coherent family of widgets, with concrete factories enforcing family-internal consistency.

A step-by-step construction surface where each step is named after what it sets, optional inputs are explicit, and the moment of 'now build it' is a separate, terminal call.

The base class owns the workflow and exposes one virtual hook — the factory method — that subclasses override to choose the product.

Variants live as configured prototype instances in a registry; creation is clone + tweak.

Exactly one instance exists for the system's lifetime; every consumer reaches that instance through a single named access point.

One wrapper class adapts the legacy or third-party interface to the canonical one the rest of the system uses.

Two hierarchies that compose: an abstraction holds a reference to its implementation and delegates the variable part.

Leaf and composite share an interface; the composite's implementation of any operation delegates to its children.

Each cross-cutting feature is a separate wrapper class that conforms to the same interface as the wrappee.

One named entry point that owns the choreography.

Intrinsic state (the kind-shared data) lives in one Flyweight object per kind; extrinsic state (the per-instance data: position, scale, custom parameters) lives on the instance.

A Proxy that conforms to the real subject's interface and decides — based on the proxy's responsibility (lazy load, access control, caching, remote dispatch) — when and whether to forward to the real object.

Each concern is a small handler class that decides whether to handle the request or forward it down the chain.

Each operation is a first-class object with execute() and (where reversible) undo().

Each grammar rule becomes a class with an interpret(context) method.

The collection exposes one iterator-shaped surface (next() / done); consumers use it without knowing the underlying representation.

Each collaborator knows one Mediator; the Mediator owns the coordination logic.

The object exposes save() returning an opaque Memento and restore(memento) accepting one.

The subject exposes subscribe(observer) and an internal observer list.

Each state is a class implementing the operation interface; the host object delegates every operation to its current state object.

Each algorithm is a small class implementing one operation method; the host holds a strategy reference and delegates.

The base class owns the algorithm's skeleton as a concrete method (the template method).

Each operation is a Visitor class with one visit method per node type.