完整设计模式目录见:https://blog.csdn.net/u013523089/article/details/82852049
中介者模式:将两个本没有关联的类,关联起来;这个模式好像没啥实际用处
例:A,B没有关系,利用中介者mediator,A可以调用B 的方法,反之亦然
感觉这个没多大意义啊,可能应用场景不是很多
package com.zhaowd.test.designPattern.Mediator中介者;
public class Test {
/**
* 解释器模式:不创建类之间的关系,达到类之间交互的目的
* @param args
*/
public static void main(String[] args) {
Colleague colleagueA = new ConcreteColleagueA();
Colleague colleagueB = new ConcreteColleagueB();
Mediator mediator = new ConcreteMediator(colleagueA, colleagueB);
colleagueA.setMediator(mediator);
colleagueB.setMediator(mediator);
((ConcreteColleagueA) colleagueA).notifyColleagueB();
((ConcreteColleagueB) colleagueB).notifyColleagueA();
}
}