Mediator
A Mediator Pattern says that "to define an object that encapsulates how a set of objects interact".
📎 Le médiateur centralise la communication entre les composants du système. Les composants ne voient quel’objet médiateur et ne communiquent pas directement.
Example​
we'll use the Mediator pattern in the context of a chatroom application. First we'll define an interface for our mediator.
While we described the Colleague as an interface above, it's more useful to use an abstract class in this case:
Now let's create our concrete mediator implementation
Finally we'll create one concrete colleage.
If we assume that we could have many different colleagues that react differently when a message is received, this pattern fits in well. For example, we could have a mobileColleague that needs to display the message differently to the desktop colleague.
Here's a client that drives the entire application: