Roadmap › 1. .NET › Step 12
DP

Design Patterns (GoF + Enterprise) in C#

Creational, structural and behavioural Gang-of-Four patterns with C# code, plus Repository, Unit of Work, CQRS, Mediator, Options and microservice patterns.
What it is & where it is used

A design pattern is a proven, reusable solution to a common design problem: a template, not finished code. The classic catalogue is Design Patterns: Elements of Reusable Object-Oriented Software (1994) by the Gang of Four (Gamma, Helm, Johnson, Vlissides), with 23 patterns in three groups:

GroupPurposePatterns
Creational (5)How objects are createdSingleton, Factory Method, Abstract Factory, Builder, Prototype
Structural (7)How objects are composedAdapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
Behavioural (11)How objects interactChain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor

Enterprise and cloud patterns used daily in .NET: Repository, Unit of Work, Dependency Injection, CQRS, Mediator (MediatR), Options, Specification, Outbox, Circuit Breaker, Retry, Saga, API Gateway.

Versions & history
YearMilestone
1977Christopher Alexander, A Pattern Language (architecture) inspires software patterns
1994GoF book: 23 patterns
1996Pattern-Oriented Software Architecture (POSA)
2002Martin Fowler, Patterns of Enterprise Application Architecture — Repository, Unit of Work, Data Mapper, Active Record
2003Eric Evans, Domain-Driven Design — Aggregates, Value Objects, Domain Events
2003Hohpe & Woolf, Enterprise Integration Patterns — messaging
2010sCloud design patterns (Microsoft Azure Architecture Center): Circuit Breaker, Retry, CQRS, Event Sourcing, Saga, Strangler Fig
Lifecycle

How to use a pattern well:

  1. Notice the problem (e.g. a growing switch on type, an awkward third-party API, object creation spread everywhere).
  2. Name the pattern that fits (Strategy, Adapter, Factory).
  3. Apply it minimally — the simplest version that solves today's problem.
  4. Test behaviour through the abstraction.
  5. Revisit — remove a pattern that adds indirection with no benefit.

Patterns are a vocabulary. Saying "I wrapped the SDK in an Adapter and added a caching Decorator" communicates a whole design in one sentence.

Tools used to develop
  • refactoring.guru — free illustrated catalogue (with C# examples).
  • dofactory.com — .NET-specific pattern examples.
  • MediatR — Mediator/CQRS pipeline library (commercial licence from v13).
  • Polly / Microsoft.Extensions.Http.Resilience — Retry, Circuit Breaker, Timeout, Bulkhead.
  • Scrutor — Decorator registration in ASP.NET Core DI.
  • Azure Architecture Center — Cloud design patterns catalogue.