The definition of the Mediator mode (mediator)
Encapsulates a series of object interactions with a mediation object. The mediator makes the objects not need to explicitly reference each other, so that they are loosely coupled, and can independently change the interaction between them.
Applicability of the Mediator mode (mediator)
1. A set of objects communicates in a well-defined but complex way, resulting in a confusing and incomprehensible structure of interdependence.
2. An object that references many other objects and communicates directly with those objects makes it difficult to reuse the object.
3. Want to customize a behavior that is distributed across multiple classes, but do not want to generate too many subclasses.
Participants in the Mediator mode (mediator)
1.Mediator
A mediator defines an interface for communicating with each colleague (colleague) object.
2.ConcreteMediator
The specific mediator realizes the collaborative behavior by coordinating the colleagues ' objects, and understands and maintains its colleagues.
3.Colleague:
Abstract colleague class.
4.Colleagueclass
Specific colleague class. Each specific colleague class needs to know its own behavior, but they need to know the mediator
The UML class diagram of the mediator mode
Specific code implementation:
First step: Define Mediator
The mediator mode of the Java Design Pattern series