Implementing the Mediator pattern
The Mediator pattern is another GoF design pattern that controls how objects interact with one another (making it a behavioral pattern).
Goal
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.
Design
Let's start with some UML diagrams. From a very high level, the Mediator pattern is composed of a mediator and colleagues:
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:
That...