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:
| Group | Purpose | Patterns |
|---|---|---|
| Creational (5) | How objects are created | Singleton, Factory Method, Abstract Factory, Builder, Prototype |
| Structural (7) | How objects are composed | Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy |
| Behavioural (11) | How objects interact | Chain 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
| Year | Milestone |
|---|---|
| 1977 | Christopher Alexander, A Pattern Language (architecture) inspires software patterns |
| 1994 | GoF book: 23 patterns |
| 1996 | Pattern-Oriented Software Architecture (POSA) |
| 2002 | Martin Fowler, Patterns of Enterprise Application Architecture — Repository, Unit of Work, Data Mapper, Active Record |
| 2003 | Eric Evans, Domain-Driven Design — Aggregates, Value Objects, Domain Events |
| 2003 | Hohpe & Woolf, Enterprise Integration Patterns — messaging |
| 2010s | Cloud design patterns (Microsoft Azure Architecture Center): Circuit Breaker, Retry, CQRS, Event Sourcing, Saga, Strangler Fig |
Lifecycle
How to use a pattern well:
- Notice the problem (e.g. a growing
switchon type, an awkward third-party API, object creation spread everywhere). - Name the pattern that fits (Strategy, Adapter, Factory).
- Apply it minimally — the simplest version that solves today's problem.
- Test behaviour through the abstraction.
- 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.