The mediator pattern is a behavioral pattern used for mediating the exchange of messages between objects.
The best analogy to a real world scenario for this batter is my thinking at an airport traffic control
tower and its dialogue with the plane's.
The police are not communicating between each other, but rather with the tower and the tower sends
the relevant messages to other planes.
This is exactly what you should achieve with the mediator pattern.
You can use this pattern whenever you have too many relationships between the objects, making the dialogue
between them too difficult.
Also, when the communication between objects is very complex, it is worth adding a mediator and untangle
some of the communication complexity.
The UML diagram for this pattern is pretty straightforward.
You have a mediator interface that is implemented by a concrete mediator class a colleague interface
will be implemented by the concrete college class.
And you can see that instead of the two colleagues communicating with each other directly, they rely
on the mediator to mediate the communication.
In our app, we will call the chat mediator and the role of the colleagues will be taken by the users
of the chat.
Let's now see the implementation for this father.