CREATIONAL PATTERNS
Creational patterns
Creational patterns control how objects are created so construction logic stays in one place instead of scattered across callers.
Factory Method
Define an interface for creating objects, but let subclasses or providers decide which concrete type to instantiate.
Architecture connection
Keeps domain code depending on abstractions, not concrete classes — essential in layered and hexagonal architectures where infrastructure swaps implementations behind ports.
LEARN MORE — Refactoring Guru — Factory Method
Singleton
Ensure a class has only one instance and provide a global access point to it.
Architecture connection
Use sparingly for true shared resources (config, connection pools). Overuse creates hidden global state that fights testability and modular boundaries.
LEARN MORE — SourceMaking — Singleton
Builder
Separate the construction of a complex object from its representation so the same process can build different variants.
Architecture connection
Pairs well with immutable domain models and API DTO assembly — configuration and object graphs stay readable as systems grow.
LEARN MORE — Refactoring Guru — Builder
Abstract Factory
Provide an interface for creating families of related objects without specifying their concrete classes.
Architecture connection
Useful when swapping entire platform stacks (UI themes, cloud providers, persistence backends) behind one factory contract at infrastructure boundaries.
LEARN MORE — Refactoring Guru — Abstract Factory
Prototype
Create new objects by copying an existing instance (prototype) instead of constructing from scratch.
Architecture connection
Supports cloning complex domain graphs and configuration templates — common when duplicating aggregates or seeding test fixtures without tight coupling to constructors.
LEARN MORE — Refactoring Guru — Prototype
STRUCTURAL PATTERNS
Structural patterns
Structural patterns compose classes and objects into larger structures while keeping interfaces stable.
Adapter
Convert the interface of a class into another interface clients expect — wrap a legacy or third-party API behind your domain contract.
Architecture connection
Core to hexagonal (ports & adapters) architecture: adapters sit at the boundary so the core never imports vendor SDKs directly.
LEARN MORE — Refactoring Guru — Adapter
Decorator
Attach additional responsibilities to an object dynamically without altering its class.
Architecture connection
Supports cross-cutting concerns (logging, caching, auth) in a composable way instead of deep inheritance trees — common in middleware pipelines.
LEARN MORE — SourceMaking — Decorator
Facade
Provide a simplified interface to a complex subsystem of classes, modules, or services.
Architecture connection
Defines module or service boundaries: callers see one entry point while internal complexity stays encapsulated — a building block of modular monoliths and microservice APIs.
LEARN MORE — Refactoring Guru — Facade
Bridge
Decouple an abstraction from its implementation so the two can vary independently.
Architecture connection
Keeps domain abstractions stable while swapping infrastructure implementations — a natural fit for hexagonal ports where the core never references concrete drivers.
LEARN MORE — Refactoring Guru — Bridge
Composite
Compose objects into tree structures to represent part-whole hierarchies; treat individual objects and compositions uniformly.
Architecture connection
Models nested domain structures (menus, org charts, file systems) and recursive operations without special-casing leaves vs. containers.
LEARN MORE — Refactoring Guru — Composite
Flyweight
Share intrinsic state among many fine-grained objects to reduce memory use when thousands of similar instances exist.
Architecture connection
Optimizes read-heavy caches and rendering pipelines — intrinsic data lives in a shared pool while extrinsic context stays per-use.
LEARN MORE — Refactoring Guru — Flyweight
Proxy
Provide a surrogate or placeholder that controls access to another object — lazy loading, caching, or access control.
Architecture connection
Common at hexagonal boundaries for remote services, permission checks, and deferred initialization without leaking infrastructure into domain code.
LEARN MORE — Refactoring Guru — Proxy
BEHAVIORAL PATTERNS
Behavioral patterns
Behavioral patterns govern communication and responsibility assignment between objects.
Observer
Define a one-to-many dependency so when one object changes state, all dependents are notified and updated automatically.
Architecture connection
Underpins event-driven and reactive architectures — domain events, pub/sub buses, and UI binding (e.g. MVVM) all use this idea.
LEARN MORE — Refactoring Guru — Observer
Strategy
Define a family of algorithms, encapsulate each one, and make them interchangeable at runtime.
Architecture connection
Enables policy and plugin slots in clean architecture — swap sorting, pricing, or AI providers without rewriting callers.
LEARN MORE — Refactoring Guru — Strategy
Command
Encapsulate a request as an object, letting you parameterize clients, queue operations, and support undo.
Architecture connection
Maps directly to CQRS and job queues: each command is a discrete unit of work crossing application boundaries with clear audit trails.
LEARN MORE — SourceMaking — Command
Chain of Responsibility
Pass a request along a chain of handlers; each handler decides whether to process it or forward it to the next.
Architecture connection
Models middleware pipelines, validation chains, and authorization filters — core to HTTP middleware and clean-architecture request pipelines.
LEARN MORE — Refactoring Guru — Chain of Responsibility
Iterator
Provide a way to traverse elements of a collection without exposing its internal representation.
Architecture connection
Standardizes pagination, streaming, and lazy enumeration across repositories and APIs — callers iterate without knowing storage details.
LEARN MORE — Refactoring Guru — Iterator
Mediator
Define an object that encapsulates how a set of objects interact, promoting loose coupling by avoiding direct references.
Architecture connection
Reduces tangled cross-module calls — chat rooms, event buses, and orchestrators often act as mediators between bounded contexts.
LEARN MORE — Refactoring Guru — Mediator
Memento
Capture and externalize an object's internal state so it can be restored later without violating encapsulation.
Architecture connection
Supports undo/redo, snapshots, and audit trails in workflow engines — state is stored separately from the object that produced it.
LEARN MORE — Refactoring Guru — Memento
State
Allow an object to alter its behavior when its internal state changes, as if the object changed its class.
Architecture connection
Models order lifecycles, connection states, and workflow transitions cleanly — each state encapsulates its own rules instead of giant switch statements.
LEARN MORE — Refactoring Guru — State
Template Method
Define the skeleton of an algorithm in a base class, letting subclasses override specific steps without changing the overall structure.
Architecture connection
Useful in framework hooks and pipeline bases — the invariant flow stays in one place while extension points live in subclasses or strategies.
LEARN MORE — Refactoring Guru — Template Method
Visitor
Represent an operation to perform on elements of an object structure; lets you add new operations without changing element classes.
Architecture connection
Powers AST walkers, report generators, and cross-cutting traversals over stable domain trees — common in compilers and DDD aggregate visitors.
LEARN MORE — Refactoring Guru — Visitor
Interpreter
Define a representation for a language grammar and an interpreter that evaluates sentences in that language.
Architecture connection
Used for rules engines, query DSLs, and policy expressions — keeps domain-specific logic declarative instead of buried in imperative code.
LEARN MORE — Refactoring Guru — Interpreter
ARCHITECTURE STYLES
Architecture styles
An architecture style organizes the system into major parts and defines how they interact. Patterns often appear inside each part.
Layered (n-tier)
Organize code into horizontal layers — presentation, application, domain, infrastructure — with dependencies pointing inward.
Architecture connection
Factory, Repository, and Facade patterns typically live at layer boundaries to keep domain rules isolated from frameworks.
LEARN MORE — Microsoft Learn — N-tier architecture
Hexagonal (ports & adapters)
Place the domain at the center; all I/O (UI, DB, messaging) connects through ports implemented by adapters.
Architecture connection
Adapter and Strategy are first-class citizens here — they are how you plug in databases, HTTP, and third-party services without polluting core logic.
LEARN MORE — Alistair Cockburn — Hexagonal architecture
MVC / MVVM
Separate user interface, application logic, and data: MVC splits Model–View–Controller; MVVM adds data binding between View and ViewModel.
Architecture connection
Observer and Command patterns support reactive UIs and user actions; keeps presentation replaceable (web, desktop, mobile) over shared domain code.
LEARN MORE — Martin Fowler — GUI architectures
Microservices (overview)
Decompose a system into independently deployable services, each owning a bounded context and communicating over the network.
Architecture connection
Facade defines service APIs; Adapter integrates legacy systems; Saga/Command patterns coordinate distributed workflows — with trade-offs in consistency and ops complexity.
LEARN MORE — Martin Fowler — Microservices
Event-Driven
Components communicate by producing and consuming events asynchronously rather than calling each other directly.
Architecture connection
Observer and Mediator underpin pub/sub buses and domain events — enables loose coupling, eventual consistency, and reactive scaling across services.
LEARN MORE — Martin Fowler — Event-Driven Architecture
Clean Architecture
Organize code in concentric rings with dependencies pointing inward — entities and use cases at the center, frameworks and UI at the edge.
Architecture connection
Formalizes ports-and-adapters thinking: Factory, Strategy, and Repository patterns live at ring boundaries to keep business rules framework-agnostic.
LEARN MORE — Robert C. Martin — Clean Architecture
Onion Architecture
Layer the application around the domain model with dependencies flowing inward; infrastructure implements interfaces defined by inner layers.
Architecture connection
Repository and Unit of Work sit at the domain–infrastructure seam; Adapter wraps external systems so the core stays persistence-ignorant.
LEARN MORE — Jeffrey Palermo — Onion Architecture
Monolithic
Build the entire application as a single deployable unit with shared memory, process, and codebase.
Architecture connection
Simplest starting point — Facade and layered boundaries still matter so the monolith can be modularized or strangler-migrated later without a rewrite.
LEARN MORE — Martin Fowler — Monolith First
SOA (Service-Oriented Architecture)
Organize capabilities as loosely coupled, discoverable services with standardized contracts, often orchestrated via an enterprise service bus.
Architecture connection
Precursor to microservices — Adapter and Facade define service contracts; emphasizes interoperability and shared governance over independent deployment.
LEARN MORE — IBM — Service-oriented architecture
DOMAIN-DRIVEN DESIGN
Domain-driven design
Domain-driven design (DDD) aligns software structure with business domains — bounded contexts, ubiquitous language, and strategic patterns keep complex systems understandable.
Domain-Driven Design
Model software around the business domain using a shared language, bounded contexts, and rich domain models instead of anemic data layers.
Architecture connection
Guides how you slice microservices and modular monoliths — each bounded context owns its aggregates, events, and anti-corruption layers at integration points.
LEARN MORE — Martin Fowler — Domain-Driven Design
Repository
Mediate between the domain and data mapping layers using a collection-like interface for accessing aggregates.
Architecture connection
Hides persistence details behind a domain-facing port — core to hexagonal, onion, and clean architectures where infrastructure implements the repository contract.
LEARN MORE — Martin Fowler — Repository
Unit of Work
Track changes to objects during a business transaction and coordinate writing them out as a single atomic operation.
Architecture connection
Pairs with Repository in application services — ensures aggregate consistency and transaction boundaries without leaking ORM session details into the domain.
LEARN MORE — Martin Fowler — Unit of Work
Anti-Corruption Layer
Translate between your domain model and an external system's model so foreign concepts do not leak into your bounded context.
Architecture connection
Adapter at the strategic level — sits between bounded contexts or legacy integrations, preserving ubiquitous language inside your core.
LEARN MORE — Microsoft Learn — Anti-corruption layer
DISTRIBUTED & CLOUD PATTERNS
Distributed & cloud patterns
These patterns address reliability, consistency, and integration challenges that arise when systems span processes, networks, and teams.
CQRS
Separate read models from write models so commands and queries can be optimized, scaled, and evolved independently.
Architecture connection
Extends the Command pattern across service boundaries — write side emits events or updates projections consumed by specialized read stores.
LEARN MORE — Martin Fowler — CQRS
Event Sourcing
Persist state as an append-only sequence of domain events rather than overwriting current state in place.
Architecture connection
Complements event-driven and CQRS architectures — Observer notifies projections; Memento-like replay reconstructs any point-in-time snapshot.
LEARN MORE — Martin Fowler — Event Sourcing
Circuit Breaker
Wrap remote calls with a breaker that opens after repeated failures, preventing cascading outages and allowing downstream recovery.
Architecture connection
Essential resilience pattern in microservices and SOA — Proxy-like wrapper around external calls with fallback and health-aware routing.
LEARN MORE — Martin Fowler — Circuit Breaker
Saga
Coordinate a long-running distributed transaction as a sequence of local transactions, each with a compensating action on failure.
Architecture connection
Replaces two-phase commit in microservices — Command and Observer patterns choreograph or orchestrate steps across bounded contexts.
LEARN MORE — Microsoft Learn — Saga
API Gateway
Provide a single entry point that routes, aggregates, authenticates, and rate-limits requests to backend services.
Architecture connection
Facade at the network edge — hides service topology from clients and centralizes cross-cutting concerns before traffic reaches individual services.
LEARN MORE — Microsoft Learn — API Gateway
BFF (Backend for Frontend)
Create a dedicated backend API tailored to the needs of a specific client (web, mobile, IoT) rather than one generic API for all.
Architecture connection
Sits behind or alongside the API Gateway — Adapter and Facade combine to shape responses per channel without bloating core domain services.
LEARN MORE — Sam Newman — Backends for Frontends
Strangler Fig
Incrementally replace a legacy system by routing new functionality to new services while the old system is gradually retired.
Architecture connection
Migration strategy for monolith-to-microservices — Adapter and Facade route traffic until the legacy core is fully displaced without a big-bang rewrite.
LEARN MORE — Martin Fowler — Strangler Fig