Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly.
You have multiple objects that need to communicate with each other, creating a tangled web of dependencies that's hard to maintain and understand.
The Mediator pattern centralizes complex communications and control logic between related objects into a single mediator object.
- A set of objects communicate in complex but well-defined ways
- Reusing an object is difficult because it communicates with many other objects
- Behavior distributed between several classes should be customizable without subclassing
See the Program.cs file for a chat room mediator coordinating team communications.
- Single Responsibility Principle - extract communications into a single place
- Open/Closed Principle - introduce new mediators without changing components
- Reduces coupling between components
- Easier to reuse individual components
- Over time a mediator can evolve into a God Object
- Can become overly complex