门面设计模式主要用在在一个大的系统中有多个子系统时,多个子系统会设计一个门面,把别的系统感兴趣的数据封闭起来,通过这个门面来进行访问

Facade

package design.pattern.facade;

public class Facade {
    private SubSystemA subA;
    private SubSystemB subB;
    
    public Facade() {
        subA = new SubSystemA();
        subB = new SubSystemB();
    }
    
    public void run() {
        subA.run();
        subB.run();
    }
}

SubSystemA

package design.pattern.facade;

public class SubSystemA {
    public void run() {
        System.out.println("SubSystemA");
    }
}

SubSystemB

package design.pattern.facade;

public class SubSystemB {
    public void run() {
        System.out.println("SubSystemB");
    }
}

Client

package design.pattern.facade;

public class Client {
    public static void main(String[] args) {
        new Facade().run();
    }
}

 

posted on 2017-10-21 20:19  啊哈咧  阅读(145)  评论(0编辑  收藏  举报