结构型模式-外观

来源:互联网 发布:cpda数据分析师考试 编辑:程序博客网 时间:2024/05/30 20:08
结构图


 
模式说明
  1. 扩展点在SubSystem集合。增加一个具体的子系统后,可能但不一定需要修改Façade外观类。
  2. 客户端需要知道具体哪一个Façade外观类。
  3. 客户端不需要关系到底哪个SubSystem类负责Façade外观类的何种任务。
  4. 外子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。


客户端

public static void main(String[] args) {Facade facade = new Facade();facade.methodA();facade.methodB();}


类设计
public class Facade {private SubSystemOne one;private SubSystemTwo two;private SubSystemThree three;private SubSystemFour four; public Facade() {one = new SubSystemOne();two = new SubSystemTwo();three = new SubSystemThree();four = new SubSystemFour();} public void methodA() {one.methodOne();three.methodThree();} public void methodB() {two.methodTwo();four.methodFour();}}public class SubSystemOne {public void methodOne() {System.out.println("method one");}}public class SubSystemTwo {public void methodTwo() {System.out.println("method two");}}public class SubSystemThree {public void methodThree() {System.out.println("method three");}}public class SubSystemFour {public void methodFour() {System.out.println("method four");}}


0 0
原创粉丝点击