Object-oriented Patterns Reference
Intent, fit, trade-offs, and relationships for major object-oriented design patterns.
Updated 2026-07-22
Abstract Factory
Provide an interface for creating related or dependent objects without exposing their concrete classes.
| Aspect | Guidance |
|---|---|
| Use when | A product family must stay compatible while its concrete implementation can vary. |
| Trade-offs | Adds factories and product interfaces; extending the family with a new product kind affects every factory. |
| Related | Factory Method, Prototype |
Builder
Separate the construction of a complex object from its final representation.
| Aspect | Guidance |
|---|---|
| Use when | Construction has ordered steps, many optional values, or multiple outputs. |
| Trade-offs | Introduces another abstraction and can be excessive for simple immutable values. |
| Related | Abstract Factory, Factory Method |
Factory Method
Define a creation operation while allowing implementations to select the concrete product.
| Aspect | Guidance |
|---|---|
| Use when | A base workflow depends on an object whose exact type varies. |
| Trade-offs | Often requires subclassing or injected creators and increases the number of types. |
| Related | Abstract Factory, Template Method |
Prototype
Create new objects by copying an existing configured object.
| Aspect | Guidance |
|---|---|
| Use when | Initialization is expensive or runtime configuration matters more than concrete classes. |
| Trade-offs | Correctly copying identity, cycles, and mutable nested state can be difficult. |
| Related | Factory Method, Memento |
Singleton
Provide one shared instance within an explicitly defined scope.
| Aspect | Guidance |
|---|---|
| Use when | Exactly one coordinator or resource owner is required for that scope. |
| Trade-offs | Creates global coupling, complicates tests, and can hide lifecycle and concurrency concerns. |
| Related | Dependency Injection, Abstract Factory |
Adapter
Convert an existing interface into the interface a client expects.
| Aspect | Guidance |
|---|---|
| Use when | Reusing a class, library, or service with an incompatible contract. |
| Trade-offs | Translation can conceal semantic mismatches and adds another layer. |
| Related | Bridge, Facade, Proxy |
Bridge
Separate an abstraction from its implementation so both dimensions can evolve independently.
| Aspect | Guidance |
|---|---|
| Use when | Two varying dimensions would otherwise create a subclass explosion. |
| Trade-offs | More indirection and up-front design are required. |
| Related | Adapter, Strategy |
Composite
Represent part-whole trees while treating leaves and containers through one interface.
| Aspect | Guidance |
|---|---|
| Use when | Clients should apply operations uniformly across a hierarchy. |
| Trade-offs | A broad common interface may allow operations that make little sense for some nodes. |
| Related | Decorator, Iterator, Visitor |
Decorator
Attach responsibilities to an object dynamically by wrapping it.
| Aspect | Guidance |
|---|---|
| Use when | Behavior must be combined independently without a large inheritance hierarchy. |
| Trade-offs | Many small wrappers complicate identity, debugging, and ordering. |
| Related | Composite, Proxy, Chain of Responsibility |
Facade
Provide a focused interface over a larger or more complex subsystem.
| Aspect | Guidance |
|---|---|
| Use when | Most clients need a stable, convenient entry point rather than full subsystem access. |
| Trade-offs | A facade can grow into an oversized coordinator or conceal useful capabilities. |
| Related | Adapter, Mediator |
Flyweight
Share intrinsic state among many fine-grained objects.
| Aspect | Guidance |
|---|---|
| Use when | A very large number of similar objects makes duplicated state expensive. |
| Trade-offs | Clients must manage external state and shared objects must remain safe to reuse. |
| Related | Composite, Factory Method |
Proxy
Use a stand-in that controls access to another object.
| Aspect | Guidance |
|---|---|
| Use when | Access needs laziness, authorization, remote communication, caching, or instrumentation. |
| Trade-offs | Adds latency and indirection; behavior can surprise clients if the proxy is not transparent. |
| Related | Adapter, Decorator |
Chain of Responsibility
Send a request through a sequence of potential handlers.
| Aspect | Guidance |
|---|---|
| Use when | The handler is not known in advance or several handlers may contribute. |
| Trade-offs | Requests may go unhandled and the effective control flow becomes less visible. |
| Related | Command, Decorator |
Command
Encapsulate a request as an object with its parameters and execution behavior.
| Aspect | Guidance |
|---|---|
| Use when | Operations need queues, retries, logs, scheduling, or undo. |
| Trade-offs | Creates extra objects and undo requires careful state capture. |
| Related | Memento, Chain of Responsibility |
Interpreter
Represent a grammar and evaluate sentences in that grammar.
| Aspect | Guidance |
|---|---|
| Use when | A small, stable language must be evaluated repeatedly. |
| Trade-offs | Large grammars become slow and hard to maintain; a parser generator may fit better. |
| Related | Composite, Visitor |
Iterator
Traverse a collection without exposing its internal representation.
| Aspect | Guidance |
|---|---|
| Use when | Clients need a uniform traversal API or multiple traversal strategies. |
| Trade-offs | Mutation during traversal and resource-backed iterators require explicit semantics. |
| Related | Composite, Visitor |
Mediator
Coordinate interactions through a dedicated object instead of many direct dependencies.
| Aspect | Guidance |
|---|---|
| Use when | A group of objects has dense, difficult-to-change communication. |
| Trade-offs | The mediator can accumulate too many responsibilities. |
| Related | Observer, Facade |
Memento
Capture an object’s state without exposing its implementation so it can later be restored.
| Aspect | Guidance |
|---|---|
| Use when | Undo, checkpoints, or rollback must preserve encapsulation. |
| Trade-offs | Snapshots may consume substantial memory and can become invalid as schemas evolve. |
| Related | Command, Prototype |
Observer
Notify registered dependents when a subject changes.
| Aspect | Guidance |
|---|---|
| Use when | Multiple consumers react to state changes without tight coupling. |
| Trade-offs | Notification order, failures, reentrancy, and subscriber lifetimes require clear rules. |
| Related | Mediator, Event-driven Consumer |
State
Delegate behavior to an object representing the current state.
| Aspect | Guidance |
|---|---|
| Use when | Conditionals vary behavior across a well-defined state machine. |
| Trade-offs | Adds types and transition ownership must be designed carefully. |
| Related | Strategy, Template Method |
Strategy
Encapsulate interchangeable algorithms behind one contract.
| Aspect | Guidance |
|---|---|
| Use when | A behavior varies independently from the client that uses it. |
| Trade-offs | Clients or configuration must choose correctly, and tiny strategies may add noise. |
| Related | State, Bridge, Template Method |
Template Method
Define an algorithm skeleton while allowing selected steps to vary.
| Aspect | Guidance |
|---|---|
| Use when | Related workflows share ordering and invariant steps. |
| Trade-offs | Inheritance couples variants to the base class and hook methods can obscure flow. |
| Related | Factory Method, Strategy |
Visitor
Define operations over a stable object structure without changing its element types.
| Aspect | Guidance |
|---|---|
| Use when | Many unrelated operations target a hierarchy whose element types rarely change. |
| Trade-offs | Adding element types affects every visitor and traversal can expose internals. |
| Related | Composite, Iterator |
Dependency Injection
Supply an object’s collaborators from outside rather than constructing them internally.
| Aspect | Guidance |
|---|---|
| Use when | Implementations, lifetimes, or test doubles must vary independently. |
| Trade-offs | Object assembly moves elsewhere and runtime containers may hide the dependency graph. |
| Related | Abstract Factory, Strategy |
Null Object
Represent the absence of behavior with an object that honors the expected contract.
| Aspect | Guidance |
|---|---|
| Use when | Optional collaborators otherwise require repeated null checks. |
| Trade-offs | Can hide missing configuration or failures when absence should be explicit. |
| Related | Strategy, Special Case |
Specification
Represent a business predicate as a named, composable object.
| Aspect | Guidance |
|---|---|
| Use when | Rules must be reused, combined, explained, or translated into queries. |
| Trade-offs | Too many small specifications can obscure simple rules and translation support is limited. |
| Related | Composite, Strategy |