外观模式(Facade):为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,
这个接口使得这一个子系统更加容易使用
下面是类结构图:
下面是源代码:
SubSystemOne.java
package com.china_chenglong;
public class SubSystemOne {
public void sayOne(){
System.out.println("say one");
}
}
SubSystemTwo.java
package com.china_chenglong;
public class SubSystemTwo {
public void sayTwo(){
System.out.println("say two");
}
}
SubSystemThree.java package com.china_chenglong; public class SubSystemThree { public void sayThree(){ System.out.println("say three"); } } Facade.java package com.china_chenglong; public class Facade { private SubSystemOne one; private SubSystemTwo two; private SubSystemThree three; public Facade(){ one = new SubSystemOne(); two = new SubSystemTwo(); three = new SubSystemThree(); } public void Say(){ one.sayOne(); two.sayTwo(); three.sayThree(); } } MainClass.java package com.china_chenglong; public class MainClass { public static void main(String[] args) { Facade facade = new Facade(); facade.Say(); } }