[Design mode-behavior type] Mediator Mode)

Source: Internet
Author: User

[Design mode-behavior type] Mediator Mode)
One sentence

It is also translated into the mediation mode.

It is similar to a real estate agent. Buyers and sellers do not need to negotiate with each other directly.

 

 

Summary

 

Analysis

MEDIATOR-four MM players playing mahjong. It is unclear who should pay for each other. Fortunately, I was there and counted the money based on their chips, if you make money, you can get it from me. If you lose the money, you can pay it to me. Everything is OK. You get a phone number of four MM.
Called by mode: The called by mode encapsulates a series of ways in which objects interact, so that these objects do not have to interact explicitly. So that they can be loosely coupled. When the roles of some objects change, the roles of other objects are not immediately affected. Ensure that these functions can be changed independently of each other. The mediator mode converts the multi-to-many interaction into one-to-many interaction. The mediation mode abstracts the behavior and collaboration of objects, and processes the interaction between objects and other objects on a small scale.

 

Instance

As an example of a real estate transaction, there is no need to pay property tax for houses that have been in the second-hand housing market for more than five years.

Including class files:

Mediator. java APIs)

An intermediary implementation class: (MediatorImpl. java)

A homeowner's interface (HouseOwner. java)

Classes of the two homekeepers (HouseOwnerA. java, HouseOwnerB. java)

Test main class: (TestMain. java)

 

 

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;public abstract class Mediator {public abstract void sellHouse(String houseType);}

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;/** * @author Administrator * */public class MediatorImpl extends Mediator {private HouseOwnerA ha;private HouseOwnerB hb;public MediatorImpl(){ha = new HouseOwnerA();hb = new HouseOwnerB();}@Overridepublic void sellHouse(String houseType) {// TODO Auto-generated method stubif(houseType.equals(typeA)){ha.sell();}else if(houseType.equals(typeB)){hb.sell();}}}

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;/** * @author Administrator *  */public abstract class HouseOwner {public abstract void sell() ;}

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;/** * @author Administrator *  */public class HouseOwnerA extends HouseOwner {@Overridepublic void sell() {// TODO Auto-generated method stubSystem.out.println(Sell house with Tax);}}

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;/** * @author Administrator * */public class HouseOwnerB extends HouseOwner {@Overridepublic void sell() {// TODO Auto-generated method stubSystem.out.println(Sell house without Tax);}}

/**    * @author oscar999    * @date 2015-1-6 * @version V1.0    */package designptn.mediator;/** * @author Administrator * */public class TestMain {public static void main(String[] args) {// TODO Auto-generated method stubMediator mediator = new MediatorImpl();mediator.sellHouse(typeA);mediator.sellHouse(typeB);}}


 

 

 

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.