Mediator definition: A Mediation object is used to encapsulate a series of object interaction behaviors. There are so many interactions between objects using Mediator Mode/mediation mode, the behavior of each object depends on each other, modifies the behavior of an object, and involves modifying the behavior of many other objects, and if you use Mediator mode, you can loosely decouple the objects. Only concern and mediator relationship, make many-to-many relationship into a one-to-many relationship, can reduce the complexity of the system, improve the scalability of the changes. How to use mediation mode first has an interface that defines the interaction between member objects:
Public interface Mediator {}
Meiator specifically implement the content of the interactive operation:
Public class Implements // Assume there are currently two members. Private New Privatenew ConcreteColleague2 (); ...}
Look at the other participant: Members, because it is interactive, both need to provide some common interface, this requirement is the same in visitor observer and other modes.
public class colleague { mediator mediator; public Mediator Getmediator () { Span style= "color: #0000ff;" >return mediator; public void Setmediator (Mediator mediator) { mediator; }} public class ConcreteColleague1 {} public class ConcreteColleague2 {}
Each member must know mediator and contact mediator instead of contacting other members.
At this point, the Mediator model framework is completed, you can find that mediator model is not a lot of rules, the general framework is relatively simple, but the actual use is very flexible.
Mediator mode in the event-driven applications, such as interface design GUI, chat, messaging, etc., in the chat application, need to have a messagemediator, specifically responsible for the request/reponse between the tasks of the adjustment.
MVC is a basic pattern of the Java EE, and View Controller is a mediator, which is the mediator between the JSP and the application on the server.
Java Mediation Mode (mediator mode)