一、介绍
外观模式(Facade),为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
二、代码实现
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("子系统方法三"); } } public class SubSystemFour { public void methodFour(){ System.out.println("子系统方法四"); } } //外观类 public class Facade { SubSystemOne one; SubSystemTwo two; SubSystemThree three; SubSystemFour four; public Facade() { this.one = new SubSystemOne(); this.two = new SubSystemTwo(); this.three = new SubSystemThree(); this.four = new SubSystemFour(); } public void MethodA(){ one.methodOne(); two.methodTwo(); three.methodThree(); four.methodFour(); } public void methodB(){ two.methodTwo(); three.methodThree(); } } public static void main(String[] args) { Facade facade = new Facade(); facade.methodB(); }