设计模式一外观模式

外观模式
  • 为一个复杂的模块或子系统提供一个外界访问的接口
  • 子系统相对独立,外界对子系统的访问只要黑箱操作即可
  • 通过为多个复杂的子系统提供一个一致的接口,而使这些子系统更加容易被访问的模式
 外观(Facade)角色:为多个子系统对外提供一个共同的接口。
子系统(Sub System)角色:实现系统的部分功能,客户可以通过外观角色访问它。
客户(Client)角色:通过一个外观角色访问各个子系统的功能。
 1 public class Facade {
 2     public static void main(String[] args) {
 3         new total().methods();
 4     }
 5 }
 6 
 7 //外观角色
 8 class total {
 9     private one one = new one();
10     private two two = new two();
11     private three three = new three();
12 
13     public void methods() {
14         one.method1();
15         two.method2();
16         three.method3();
17     }
18 }
19 
20 //子系统
21 class two {
22     public void method2() {
23         System.out.println("方法1");
24     }
25 }
26 
27 class three {
28     public void method3() {
29         System.out.println("方法2");
30     }
31 }
32 
33 class one {
34     public void method1() {
35         System.out.println("方法3");
36     }
37 }

猜你喜欢

转载自www.cnblogs.com/loveer/p/11279293.html
今日推荐