Design patterns
The classic catalogue of solutions to recurring design problems, and the vocabulary to talk about them.
Creational patterns
Factory Method
Let a method decide which concrete class to instantiate, without the caller knowing.
Used in projectsAbstract Factory
Create families of related objects without tying yourself to their concrete classes.
Used in projectsBuilder
Build a complex object step by step. In .NET you see it in WebApplicationBuilder.
Used in projectsSingleton
A single shared instance. These days the DI container handles it, not hand-written code.
Used in projectsPrototype
Create new objects by cloning an existing one, when building from scratch is expensive.
LearningStructural patterns
Adapter
Wrap an incompatible interface so it fits the one the client expects.
Used in projectsDecorator
Add behaviour by wrapping the object, without touching it or inheriting from it.
Used in projectsFacade
A simple interface in front of a complicated subsystem.
Used in projectsProxy
A stand-in that controls access to the real object: caching, permissions or lazy loading.
Used in projectsComposite
Treat a single object and a group of them the same way, through a tree structure.
Used in projectsBridge
Separate an abstraction from its implementation so both can evolve independently.
LearningFlyweight
Share common state across many objects so it is not duplicated in memory.
LearningBehavioural patterns
Strategy
Wrap interchangeable algorithms behind one interface and pick one at runtime.
Used in projectsObserver
Notify several interested parties when something changes. The basis of events and Rx.
Used in projectsMediator
Centralise communication so components never know each other. Exactly what MediatR does.
Used in projectsCommand
Package a request as an object, so it can be queued, logged or undone.
Used in projectsChain of Responsibility
Pass the request along a chain of handlers. The ASP.NET Core middleware pipeline is this.
Used in projectsTemplate Method
Define the skeleton of an algorithm and let subclasses fill in some of the steps.
Used in projectsIterator
Walk a collection without exposing how it is built inside. In .NET that is IEnumerable.
Used in projectsState
Change an object's behaviour with its state, instead of filling it with conditionals.
Used in projectsMemento
Capture an object's internal state so it can be restored later, without breaking encapsulation.
LearningVisitor
Add new operations over a structure of objects without modifying their classes.
Learning