# 外观模式
外观模式隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。它属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。
# UML 类图
# 传统的 Java 类图

# 作用
降低访问复杂系统的内部子系统时的复杂度,简化客户端与之的接口。
# 优缺点
# 优点
- 减少系统相互依赖 
- 提高灵活性 
- 提高了安全性 
# 缺点
- 不符合开闭原则
# 场景
没找到合适的
# 实现代码
/*
 * @Author: Rainy
 * @Date: 2019-11-14 19:25:01
 * @LastEditors  : Rainy
 * @LastEditTime : 2019-12-23 19:55:49
 */
class Shape {
  draw(): void {}
}
class Square {
  shape: Shape;
  constructor(shape: Shape) {
    this.shape = shape;
  }
  draw(): void {
    this.shape.draw();
  }
}
class Star {
  shape: Shape;
  constructor(shape: Shape) {
    this.shape = shape;
  }
  draw(): void {
    this.shape.draw();
  }
}
class ShapeMaker {
  square: Square;
  star: Star;
  constructor(square: Square, star: Star) {
    this.square = square;
    this.star = star;
  }
  drawStar(): void {
    this.star.draw();
  }
  drawSquare(): void {
    this.square.draw();
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52