Skip to content
DevPedia

Design patterns

Solutions to recurring design problems: how they work, when to apply them, and when a simpler alternative is the better call.

28 guides

  1. What are design patterns?

    What makes a solution a design pattern, how the classic catalog is organized, and why every pattern has to be adapted to the problem.

Creational patterns

  1. Creational patterns

    The way objects are created shapes the design too. How to separate their construction from the code that uses them, and how to pick the right pattern.

  2. Factory Method

    How to delegate the choice of which object gets created to subclasses, without coupling the calling code to a concrete class.

  3. Abstract Factory

    How to create families of compatible objects without depending on their concrete classes, and keep that compatibility when the implementation changes.

  4. Builder

    How to construct objects step by step when a constructor with many parameters becomes hard to use and maintain.

  5. Prototype

    Creating objects from existing ones can simplify their construction. How cloning works and what it demands care with.

  6. Singleton

    How to guarantee a single instance, and what offering global access to it means for dependencies and tests.

Structural patterns

  1. Structural patterns

    How to combine classes and objects to adapt interfaces, extend behavior, and simplify the use of complex components.

  2. Adapter

    How to integrate components with incompatible interfaces through an adapter, without modifying their implementations.

  3. Bridge

    How to separate an abstraction from its implementation so both can evolve without creating a subclass for every combination.

  4. Composite

    How to work with individual objects and groups of objects through one interface, simplifying how hierarchical structures are handled.

  5. Decorator

    How to add behavior to an object through composition and combine extensions without creating a subclass for every variant.

  6. Facade

    How to offer a simple interface over a complex subsystem so its clients don't have to coordinate every component.

  7. Flyweight

    When many objects share information, storing it once can cut memory use. How to separate shared state from the state that depends on each context.

  8. Proxy

    How to control access to an object through a stand-in with the same interface, and when that turns out to be useful.

Behavioral patterns

  1. Behavioral patterns

    How to distribute responsibilities and coordinate objects without making their interactions hard to maintain.

  2. Chain of Responsibility

    How to process a request through a chain of handlers and decouple the sender from whoever can handle it.

  3. Command

    How to represent actions as objects so you can queue them, log them, or allow undoing them, separated from the code that invokes them.

  4. Interpreter

    How to represent the rules of a simple language as objects and combine them to interpret expressions.

  5. Iterator

    How to traverse a collection without exposing its internal structure or coupling the traversal to a concrete implementation.

  6. Mediator

    How to centralize coordination between objects to reduce their direct dependencies and simplify their interactions.

  7. Memento

    How to save and restore an object's state without exposing its internal details.

  8. Observer

    How to notify subscribed objects of changes without depending on their concrete classes, and what that relationship means for the design.

  9. State

    How to organize an object's behavior by its state and make the allowed transitions explicit.

  10. Strategy

    How to encapsulate variants of an algorithm and swap them without modifying the code that uses them.

  11. Template Method

    How to define an algorithm's sequence in a base class and let subclasses adapt specific steps.

  12. Visitor

    How to add operations over a structure of objects without modifying their classes each time, and where this approach runs out.

Comparisons and reference

  1. Design patterns that are often confused

    Some patterns have similar structures but solve different problems. What sets them apart and how to recognize when to use each.

Search by concept, pattern or practice.