定义
要求一个子系统的外部与其内部的通信必须通过一个统一对象进行。外观模式提供一个高层次的接口,使得子系统更易使用。提供一个同一个接口,内部的逻辑在外观类处理。
类图
代码
public class FacadePattern {
public static void main(String[] args) {
System.out.println( new Facade().prove());
}
}
class SubFlow1{
boolean isTrue(){return true;}
}
class SubFlow2{
boolean isOk(){return true;}
}
class SubFlow3{
boolean isGoodMan(){ return true;
}
}
class Facade{
SubFlow1 s1 = new SubFlow1();
SubFlow2 s2 = new SubFlow2();
SubFlow3 s3 = new SubFlow3();
boolean prove(){
return s1.isTrue()&&s2.isOk()&&s3.isGoodMan();
}
}
场景
本来是一对多,现在只要一对一。