What is the mediator pattern?
Suppose you have four services, objects, or elements in your application, and these services, objects, or elements need to communicate generally to each other. ServiceA needs to talk to ServiceB and ServiceD, and ServiceC needs to talk to ServiceB and ServiceD, while ServiceB also needs to talk to ServiceD. These services, objects, and elements are now tightly coupled with each other.
Here comes the Mediator to the rescue. Instead of services, objects, or elements calling each other, we will put a mediator in the middle. The mediator acts like an airport traffic control tower that knows how we want our services to communicate with each other, as shown in the following figure:
The mediator in Figure 6.3 is the traffic control tower that handles the communication between the services, objects, or elements (the airplanes in this case).
S,o how do you do or implement the...