- What is mediator pattern in Java?
- How does mediator pattern work?
- Why use the mediator pattern?
- How do you use a mediator design pattern?
What is mediator pattern in Java?
Mediator is a behavioral design pattern that reduces coupling between components of a program by making them communicate indirectly, through a special mediator object. The Mediator makes it easy to modify, extend and reuse individual components because they're no longer dependent on the dozens of other classes.
How does mediator pattern work?
With the mediator pattern, communication between objects is encapsulated within a mediator object. Objects no longer communicate directly with each other, but instead communicate through the mediator. This reduces the dependencies between communicating objects, thereby reducing coupling.
Why use the mediator pattern?
Mediator pattern is used to reduce communication complexity between multiple objects or classes. This pattern provides a mediator class which normally handles all the communications between different classes and supports easy maintenance of the code by loose coupling.
How do you use a mediator design pattern?
The Mediator pattern suggests that you should cease all direct communication between the components which you want to make independent of each other. Instead, these components must collaborate indirectly, by calling a special mediator object that redirects the calls to appropriate components.