0%

设计模式-外观模式

隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口
降低访问复杂系统的内部子系统时的复杂度,简化客户端之间的接口。

示例

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
//子系统
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine("子系统一")
}
}
class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine("子系统二")
}
}
class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine("子系统三")
}
}
//外观类
class Facade
{
SubSystemOne one;
SubSystemOne two;
SubSystemOne three;
public Facade()
{
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
}
public void MethodA()
{
one.MethodOne();
two.MethodTwo();
three.MethodThree();
}
public void MethodB()
{
one.MethodOne();
three.MethodThree();
}
}
//Client
Facade facade = new Facade();
facade.MethodA();
facade.MethodB();