|
@@ -0,0 +1,34 @@
|
|
|
|
|
+package cn.qinys.learn.behavioral.facade;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 外观类:为客户端提供简化接口,组合多个子系统操作
|
|
|
|
|
+ */
|
|
|
|
|
+public class Facade {
|
|
|
|
|
+ private final SubsystemA a = new SubsystemA();
|
|
|
|
|
+ private final SubsystemB b = new SubsystemB();
|
|
|
|
|
+ private final SubsystemC c = new SubsystemC();
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 执行一个复杂操作,内部调用多个子系统
|
|
|
|
|
+ * @return 组合各子系统返回值的描述字符串,便于测试断言
|
|
|
|
|
+ */
|
|
|
|
|
+ public String performComplexOperation() {
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ sb.append(a.operationA1()).append(" | ");
|
|
|
|
|
+ sb.append(b.operationB1()).append(" | ");
|
|
|
|
|
+ sb.append(c.operationC1());
|
|
|
|
|
+ String res = sb.toString();
|
|
|
|
|
+ System.out.println("Facade: performComplexOperation -> " + res);
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 另一个更简单的操作示例
|
|
|
|
|
+ */
|
|
|
|
|
+ public String performSimpleOperation() {
|
|
|
|
|
+ String res = a.operationA2();
|
|
|
|
|
+ System.out.println("Facade: performSimpleOperation -> " + res);
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|