Java设计模式《八》外观模式

来源:互联网 发布:淘宝代运营收费标准 编辑:程序博客网 时间:2024/06/05 20:51
//外观模式为子系统中的一组接口提供一个一致的界面,//此模式定义了一个高层接口//这个接口是的这一子系统更加容易使用

Facade类

 public class Facade{    SubSystemOne one;    SubSystemTwo two;    SubSystemThree three;    SubSystemFour four;    public Facade(){        one = new SubSystemOne();        two = new SubSystemTwo();        three = new SubSystemThree();        four = new SubSystemFour();    }    public void methodA(){        System.out.println("method Group A");        one.methodOne();        two.methodTwo();        four.methodFour();    }    public void methodB(){        System.out.println("method group B");        one.methodOne();        three.methodThree();    }}

具体的实例

class SubSystemOne {    public void methodOne(){        System.out.println("SubSystemOne");    }}class SubSystemTwo {    public void methodTwo(){        System.out.println("SubSystemTwo");    }}class SubSystemThree {    public void methodThree(){        System.out.println("SubSystemThree");    }}class SubSystemFour {    public void methodFour(){        System.out.println("SubSystemFour");    }}

测试案例

//外观模式为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口//这个接口是的这一子系统更加容易使用public class TestFacade{    public static void main(String[] args){        Facade f = new Facade();        f.methodA();        f.methodB();    }}
0 0
原创粉丝点击