Intermediary mode in Design Mode

Source: Internet
Author: User

I. mode definition:

An intermediary object is used to encapsulate a series of object interactions. The intermediary makes the objects do not need to be explicitly referenced to each other, so that the coupling is loose and the interaction between them can be changed independently.

Ii. Structure Diagram


1) Abstract intermediary: defines the objects of a Colleague to MediatiZ intermediary? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcqOpttTP87XEvdO/records + CqGhoaEyKSC + records/PW0L3p1d/J + records/+ y/nT0LXEvt/records + 8 + iz/LB7c3itcS + expires/expires + 1vc2sysK21M/ztcS907/expires + 82sysK21M/zoaM8YnI + CjwvcD4KPHA + expires + CjxwcmUgY2xhc3M9 "brush: java; "> import java. util. arrayList; abstract class AbstractMediator {public abstract void register) {this. med = mediator;} public abstract void action (); public void changed () {med. colleagueChanged (this) ;}} class ConcreteMediator extends AbstractMediator {private ArrayList colleagueList = new ArrayList (); public void register (AbstractColleague ac) {colleagueList. add (ac);} public void ColleagueChanged (AbstractColleague ac) {for (int I = 0; I V. Advantages and Disadvantages
1) Reduce the number of sub-classes that generate Mediator to aggregate the behaviors originally distributed among multiple objects. to change these actions, you only need to generate the sub-classes of Mediator. In this way, each Colleague class can be reused.
2) It decouples the colleags. Mediator facilitates the loose coupling between different colleags. You can independently change and reuse different colleags and Mediator classes.
3) It simplifies object protocols and replaces multiple-to-many interactions with Mediator and colleags. One-to-multiple relationships are easier to understand, maintain, and expand.
4) It abstracts how objects collaborate and uses mediation as an independent concept and encapsulates it in an object, this allows you to focus on the interaction between objects. This helps to figure out how objects in a system interact.
5) It centralizes control, and the intermediary mode changes the complexity of interaction into the complexity of the intermediary. Because the intermediary encapsulates the Protocol, it may become more complex than any other Colleague. This may make the intermediary itself a giant that is difficult to maintain.
Vi. Applicability
1) A group of objects communicate in a well-defined but complex manner. The resulting dependency structure is confusing and hard to understand.
2) an object references many other objects and communicates directly with these objects, making it difficult to reuse the object.

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.