23种设计模式之外观模式
外观模式(Facade):为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
package designMode.facade; class SubSystemOne { public void methodOne(){ System.out.println("子系统方法一"); } } class SubSystemTwo { public void methodTwo(){ System.out.println("子系统方法二"); } } class SubSystemThree { public void methodThree(){ System.out.println("子系统方法三"); } } class SubSystemFour { public void methodFour(){ System.out.println("子系统方法四"); } }
package designMode.facade; 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("方法组A..."); one.methodOne(); two.methodTwo(); four.methodFour(); } public void methodB(){ System.out.println("方法组B..."); two.methodTwo(); three.methodThree(); } }
package designMode.facade; class Test { public static void main(String[] args) { Facade facade = new Facade(); facade.methodA(); facade.methodB(); } }