Software Design Pattern Catalog
85 software design patterns with Java/Spring code: GoF, enterprise, integration, microservice, resilience and data patterns, plus when not to use each.
Design Patterns (GoF)
Gamma, Helm, Johnson, Vlissides · Head First Design Patterns
Creational
- Factory Method — Let a method decide which concrete class to instantiate.
- Abstract Factory — Create families of related objects that must be used together.
- Builder — Construct complex objects step by step with readable code.
- Prototype — Create new objects by copying a configured example.
- Singleton — Guarantee one instance — usually better handled by your DI container.
Structural
- Adapter — Make an incompatible interface look like the one you expect.
- Decorator — Wrap an object to add behaviour without changing it.
- Facade — Offer one simple entry point to a complicated subsystem.
- Proxy — A stand-in that controls access: lazy, caching, remote or security.
- Composite — Treat single items and groups of items the same way.
- Bridge — Separate an abstraction from its implementation so both can vary.
Behavioural
- Strategy — Swap interchangeable algorithms behind one interface.
- Observer — Notify interested parties when something happens.
- Command — Turn a request into an object you can queue, log, retry or undo.
- State — Let an object change behaviour when its internal state changes.
- Template Method — Fix an algorithm’s skeleton and let subclasses fill in steps.
- Chain of Responsibility — Pass a request along a chain of handlers.
- Mediator — Centralise complex communication between many objects.
- Iterator — Traverse a collection without exposing its internals.
Enterprise Application Patterns
Martin Fowler — Patterns of Enterprise Application Architecture
Domain Logic
- Transaction Script — Organise business logic as one procedure per request.
- Domain Model — An object model where data and behaviour live together.
- Table Module — One object handles the logic for all rows of a table.
- Service Layer — Define the application boundary and its available operations.
Data Source Architecture
- Table Data Gateway — One object holds all SQL for one table.
- Row Data Gateway — One object per database row, with no domain logic.
- Active Record — A domain object that also loads and saves itself.
- Data Mapper — A separate layer moves data between objects and tables.
Object-Relational
- Unit of Work — Track changed objects and write them in one transaction.
- Identity Map — Load each database row into at most one object per session.
- Lazy Load — Delay loading data until it is actually needed.
- Identity Field — Keep the database id inside the object.
- Repository — A collection-like interface for accessing domain objects.
- Foreign Key Mapping — Map object references to foreign keys between tables.
- Single Table Inheritance — Store a class hierarchy in one table with a type column.
Web Presentation
- Model View Controller — Split UI into model, view and input-handling controller.
- Front Controller — One handler receives every request and dispatches it.
- Page Controller — One controller per page or action.
- Application Controller — Centralise screen navigation and flow logic.
- Template View — Render HTML by embedding markers in a page template.
Distribution
- Remote Facade — A coarse-grained facade over fine-grained objects for remote callers.
- Data Transfer Object — A simple object that carries data across a process boundary.
Offline Concurrency
- Optimistic Offline Lock — Detect conflicting edits at commit time using a version.
- Pessimistic Offline Lock — Prevent conflicts by locking data for the whole business transaction.
Session State
- Client Session State — Keep session state on the client (cookies, tokens, hidden fields).
- Server Session State — Keep session state in server memory or a session store.
- Database Session State — Store session state as data in the database.
Base Patterns
- Gateway — Wrap access to an external system behind your own interface.
- Money — Represent monetary values with amount and currency, never floats.
- Special Case — A subclass that handles a special situation instead of null checks.
- Plugin — Link implementations at configuration time, not compile time.
Enterprise Integration Patterns
Gregor Hohpe & Bobby Woolf — Enterprise Integration Patterns
Messaging Channels
- Message Channel — A named pipe that connects a sender to receivers.
- Point-to-Point Channel — Each message is consumed by exactly one receiver.
- Publish-Subscribe Channel — Each message is delivered to every subscriber.
- Dead Letter Channel — Park messages that cannot be processed so they do not block others.
- Guaranteed Delivery — Persist messages so they survive crashes.
Message Construction
- Event Message — A message that announces something happened.
- Command Message — A message that asks a receiver to do something.
- Correlation Identifier — Tag messages so replies and related messages can be matched.
Message Routing
- Content-Based Router — Route each message based on its content.
- Splitter & Aggregator — Split a message into parts, then combine related results.
- Process Manager — A central component that drives a multi-step message flow.
- Message Translator — Convert messages between different formats.
Messaging Endpoints
- Competing Consumers — Many consumers share one channel to process messages in parallel.
- Idempotent Receiver — Safely handle the same message more than once.
- Transactional Client — Tie message send/receive to a transaction boundary.
System Management
- Claim Check — Store a large payload elsewhere and send only a reference.
Microservice & Architecture Patterns
Building Microservices · Software Architecture · DDD
Microservices
- API Gateway — One entry point that routes, authenticates and shapes client traffic.
- Backends for Frontends — A dedicated backend per client type (web, mobile, partner).
- Strangler Fig — Replace a legacy system piece by piece behind a routing layer.
- Anti-Corruption Layer — Translate another model so it does not leak into yours.
- Database per Service — Each service owns its data; others go through its API.
- Sidecar — Run cross-cutting infrastructure next to each service instance.
Resilience Patterns
Building Microservices · general production practice
Resilience
- Timeout — Never wait forever for a remote call.
- Retry with Backoff & Jitter — Retry transient failures with growing, randomised delays.
- Circuit Breaker — Stop calling a failing dependency and fail fast.
- Bulkhead — Isolate resources so one failure cannot sink everything.
- Rate Limiter — Cap how many requests a client or dependency can make.
- Graceful Degradation & Fallback — Serve a reduced experience instead of an error.
Data Patterns
Designing Data-Intensive Applications · Building Microservices
Data Management
- Saga — A sequence of local transactions with compensations on failure.
- Transactional Outbox — Write the event in the same DB transaction, publish it afterwards.
- CQRS — Separate the write model from read models.
- Event Sourcing — Store state as an append-only sequence of events.
- Cache-Aside — Read from cache, fall back to the database and populate the cache.
- Idempotency Key — A client-supplied key that makes a request safe to repeat.
- Change Data Capture — Stream every database change as an event.