-
Book Overview & Buying
-
Table Of Contents
An Atypical ASP.NET Core 5 Design Patterns Guide
By :
The Mediator pattern is another GoF design pattern that controls how objects interact with one another (making it a behavioral pattern).
The mediator's role is to manage the communication between objects (colleagues). Those colleagues should not communicate together directly but use the mediator instead. The mediator helps break tight coupling between these colleagues.
To keep it short, a mediator is a middleman that relays messages between colleagues.
Let's start with some UML diagrams. From a very high level, the Mediator pattern is composed of a mediator and colleagues:
Figure 14.3 – Class diagram representing the Mediator pattern
When an object in the system wants to send a message to one or more colleagues, it uses the mediator. Here is an example of how it works:
Figure 14.4 – Sequence diagram of a mediator relaying messages to colleagues
That...