Software Engineering Architecture Lab

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

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

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

Session State

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 Construction

Message Routing

Messaging Endpoints

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

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.