-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path桥接模式.cs
93 lines (85 loc) · 2.18 KB
/
桥接模式.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using Xunit;
namespace DesignMode
{
/// <summary>
///将抽象部分与它的实现部分分离,使它们都可以独立地变化
/// </summary>
public class 桥接模式
{
[Fact]
public void Test()
{
HandsetBrand brand;
brand = new HandsetBrandN();
brand.SetHandsetSoft(new HandsetGame());
brand.Run();
brand.SetHandsetSoft(new HandsetAddressList());
brand.Run();
brand = new HandsetBrandM();
brand.SetHandsetSoft(new HandsetGame());
brand.Run();
brand.SetHandsetSoft(new HandsetAddressList());
brand.Run();
}
/// <summary>
/// 手机软件
/// </summary>
abstract class HandsetSoft
{
public abstract void Run();
}
/// <summary>
/// 手机游戏
/// </summary>
class HandsetGame : HandsetSoft
{
public override void Run()
{
Console.WriteLine("运行手机游戏");
}
}
/// <summary>
/// 手机通讯录
/// </summary>
class HandsetAddressList : HandsetSoft
{
public override void Run()
{
Console.WriteLine("运行手机通讯录");
}
}
/// <summary>
/// 手机品牌
/// </summary>
abstract class HandsetBrand
{
protected HandsetSoft _handsetSoft;
public void SetHandsetSoft(HandsetSoft handsetSoft)
{
_handsetSoft = handsetSoft;
}
public abstract void Run();
}
/// <summary>
/// 品牌N
/// </summary>
class HandsetBrandN : HandsetBrand
{
public override void Run()
{
_handsetSoft.Run();
}
}
/// <summary>
/// 品牌M
/// </summary>
class HandsetBrandM : HandsetBrand
{
public override void Run()
{
_handsetSoft.Run();
}
}
}
}