Behavioral patterns
Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects, focusing on how objects interact and communicate.
Strategy
Intent: define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.
Use cases: when you have multiple ways to perform a task (for example different sorting algorithms, payment methods or compression algorithms) and want to select one at runtime.
Observer
Intent: define a one-to-many dependency between objects, so that when one object (the subject, or observable) changes state, all its dependents (observers) are notified and updated automatically.
Use cases: implementing event-driven systems, UI event handling, and keeping related objects synchronized. C#’s eventEventsHow a class tells other classes that something happened, without knowing who is listening.Opens in a new tab and delegateDelegatesA type-safe function pointer, so a method can be passed around like any other value.Opens in a new tab mechanism provides a built-in way to implement the Observer pattern effectively and idiomatically. It’s often preferred over a manual implementation, unless you need specific customizations.
Command
Intent: encapsulate a request as an object, which lets you parameterize clients with different requests, queue or log requests, and support undoable operations.
Use cases: implementing undo and redo, queuing tasks, and decoupling the invoker of an operation from the object that knows how to perform it.
Mediator
Intent: define an object (the mediator) that encapsulates how a set of objects (colleagues) interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Use cases: managing complex communication between multiple UI components, or coordinating workflows between different services without direct dependencies between them.
The other two categories are creationalCreational patternsFour patterns for creating objects in a way that suits the situation.Opens in a new tab and structuralStructural patternsFour patterns for composing classes and objects into larger structures.Opens in a new tab.
Sources
- Mastering C# Design Patterns: Practical Examples of Singleton, Factory, and Observer, DEV · accessed May 16, 2025
- Design Patterns in C#, Refactoring.Guru · accessed May 16, 2025