Java Mediation Mode (mediator mode)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.