您的位置:首页 > 编程语言 > Java开发

Java--设计模式之外观模式

2013-12-16 17:04 405 查看
外观模式,为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层的接口,这个接口似的这一子系统更加容易使用。看例子就明白啦。

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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息