Design Patterns Guide
Welcome to the Design Patterns Guide — a comprehensive visual reference for the 23 Gang of Four (GoF) design patterns. Each pattern includes UML class diagrams and code examples in C#, Delphi, and C++.
Quick Reference
| Category | Pattern | Intent |
|---|---|---|
| Creational | Factory Method | Define an interface for creating objects, letting subclasses decide which class to instantiate |
| Abstract Factory | Create families of related objects without specifying concrete classes | |
| Builder | Separate construction of a complex object from its representation | |
| Prototype | Create new objects by cloning an existing instance | |
| Singleton | Ensure a class has only one instance with a global access point | |
| Structural | Adapter | Convert the interface of a class into another interface clients expect |
| Bridge | Decouple an abstraction from its implementation | |
| Composite | Compose objects into tree structures for part-whole hierarchies | |
| Decorator | Attach additional responsibilities to an object dynamically | |
| Facade | Provide a unified interface to a set of interfaces in a subsystem | |
| Flyweight | Use sharing to support large numbers of fine-grained objects | |
| Proxy | Provide a surrogate or placeholder for another object | |
| Behavioral | Chain of Responsibility | Pass a request along a chain of handlers |
| Command | Encapsulate a request as an object | |
| Iterator | Access elements of a collection sequentially without exposing its structure | |
| Mediator | Define an object that encapsulates how a set of objects interact | |
| Memento | Capture and restore an object’s internal state | |
| Observer | Define a one-to-many dependency between objects | |
| State | Allow an object to alter its behavior when its internal state changes | |
| Strategy | Define a family of algorithms, encapsulate each one, and make them interchangeable | |
| Template Method | Define the skeleton of an algorithm, deferring some steps to subclasses | |
| Visitor | Represent an operation to be performed on elements of an object structure | |
| Interpreter | Define a grammar representation and an interpreter to evaluate sentences |
Advanced Patterns (Modern)
| Category | Pattern | Intent |
|---|---|---|
| Cloud Resilience | Circuit Breaker | Prevent cascading failures by stopping calls to a failing service |
| Bulkhead | Isolate components so one failure doesn’t sink others | |
| Retry with Backoff | Handle transient failures by retrying with increasing delays | |
| Sidecar | Deploy auxiliary functionality in a companion process | |
| Concurrency | Actor Model | Encapsulate state in actors that communicate via async messages |
| Future / Promise | Represent a value that will be available asynchronously | |
| Reactor | Demultiplex and dispatch requests via a single-threaded event loop | |
| Object Pool | Reuse pre-allocated objects to avoid expensive creation | |
| Data & Messaging | CQRS | Separate read and write models for independent optimization |
| Event Sourcing | Persist state as a sequence of immutable events | |
| Saga | Coordinate distributed transactions with compensating actions | |
| Publish-Subscribe | Broadcast messages through a broker without sender knowing receivers | |
| DDD | Bounded Context | Define explicit boundaries for a domain model |
| Aggregate | Cluster objects into a consistency boundary with a root entity | |
| Anti-Corruption Layer | Translate between your model and an external system’s model | |
| Repository | Mediate between domain and data layers with a collection-like interface | |
| Extras | Dependency Injection | Supply dependencies from the outside for loose coupling |
| Null Object | Provide a do-nothing object to eliminate null checks | |
| MVVM | Separate UI from logic via a ViewModel with data binding | |
| Specification | Encapsulate business rules as composable predicate objects |
How This Guide Is Organized
The patterns are grouped into three categories following the original GoF classification:
- Creational Patterns — Deal with object creation mechanisms
- Structural Patterns — Deal with object composition and relationships
- Behavioral Patterns — Deal with object interaction and responsibility
- Advanced Patterns — Modern patterns for cloud, concurrency, DDD, and more
Each pattern page includes:
- Intent — what the pattern does
- Problem — when to use it
- UML Class Diagram — visual structure using Mermaid
- Participants — classes and their roles
- How It Works — step-by-step explanation
- Applicability — when to use and when not to
- Example Code — implementations in C#, Delphi, and C++
- Related Patterns — connections to other patterns