The mediator mode of the Java Design Pattern series

Source: Internet
Author: User

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

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.