外观模式,为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层的接口,这个接口似的这一子系统更加容易使用。看例子就明白啦。
1、子系统三个类
public class SubSystemOne {
public void methodOne(){
System.out.println("子系统方法一");
}
}
public class SubSystemTwo {
public void methodTwo(){
System.out.println("子系统方法二");
}
}
public class SubSystemThree {
public void methodThree(){
System.out.println("子系统方法三");
}
}
2、外观类
public class Facade {
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
public Facade(){
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
}
public void methodA(){
one.methodOne();
two.methodTwo();
three.methodThree();
}
public void methodB(){
two.methodTwo();
three.methodThree();
}
}
3、测试
public class Test {
public static void main(String[] args) {
Facade facade = new Facade();
System.out.println("方法A");
facade.methodA();
System.out.println("方法B");
facade.methodB();
}
}