中介者模式
mvc的模型,Meditor控制
/**
* Created by malei on 2016/12/6.
* 中介者接口
*/
public interface Mediator {
void listener(String key,Department de);
void say(String key);
}
/**
* Created by malei on 2016/12/6.
* 部门接口
*/
public interface Department {
void action();
}
/**
* Created by malei on 2016/12/6.
* 研发部
*/
public class Delelopment implements Department {
private final Mediator mediator;
public Delelopment(Mediator mediator){
this.mediator = mediator;
}
@Override
public void action() {
Log.show("研发部活动");
}
}
/**
* Created by malei on 2016/12/6.
* 市场部
*/
public class Market implements Department {
private final Mediator mediator;
public Market(Mediator mediator){
this.mediator = mediator;
}
@Override
public void action() {
Log.show("市场部活动");
}
public static void main(String[] args){
Mediator mediator = new CEO();
Market market = new Market(mediator);
Delelopment dev = new Delelopment(mediator);
market.action();
dev.action();
}
}
/**
* Created by malei on 2016/12/6.
* ceo:中介者的具体实现类
*/
public class CEO implements Mediator{
private Map<String, Department> map = new HashMap<String, Department>();
@Override
public void listener(String key, Department de) {
map.put(key, de);
}
@Override
public void say(String key) {
map.get(key).action();
}
}