1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Collections;
6
using System.Configuration;
7
using System.Reflection;
8
namespace KFC
9
{
10
class Program
11
{
12
static void Main(string[] args)
13
{
14
Director1 FoodBuilder = new Director1();
15
Director2 FoodBuilder2 = new Director2();
16
17
Console.WriteLine("请输入套餐编号:");
18
string no = Console.ReadLine();
19
string foodType = ConfigurationSettings.AppSettings["No" + no];
20
switch (foodType) {
21
case "NormalBuilder":
22
NormalBuilder Normal = new NormalBuilder();
23
FoodBuilder.Construct(Normal);
24
Food food = Normal.GetFoods();
25
food.Show();
26
break;
27
case "GoldBuilder":
28
GoldBuilder Gold = new GoldBuilder();
29
FoodBuilder.Construct(Gold);
30
Food GoldFood = Gold.GetFoods();
31
GoldFood.Show();
32
break;
33
case "another Director":
34
GoldBuilder GoldDirect2 = new GoldBuilder();
35
FoodBuilder2.Construct(GoldDirect2);
36
Food food2 = GoldDirect2.GetFoods();
37
food2.Show();
38
break;
39
}
40
}
41
}
42
public abstract class FoodClass {
43
public abstract void Construct(Builder builder);
44
}
45
//class FoodMamanger {
46
// public void Construct(Builder builder) {
47
//builder.BuilderHamb();
48
//builder.BuilderCoke();
49
//builder.BuilderChip();
50
// }
51
//}
52
class Director1 : FoodClass {
53
public override void Construct(Builder builder)
54
{
55
builder.BuilderHamb();
56
builder.BuilderCoke();
57
builder.BuilderChip();
58
}
59
}
60
class Director2 : FoodClass {
61
public override void Construct(Builder builder)
62
{
63
builder.BuilderChicken();
64
builder.BuilderChip();
65
builder.BuilderCoke();
66
}
67
}
68
public class Food {
69
/// <summary>
70
/// Food 食物类
71
/// </summary>
72
Hashtable food = new Hashtable();
73
public void add(string FoodName,string Price) {
74
food.Add(FoodName, Price);
75
}
76
public void Show() {
77
// IDictionaryEnumerator MyEnumerator = food.GetEnumerator();
78
79
Console.WriteLine("Food List:");
80
Console.WriteLine("---------------------");
81
string Foodlist = "";
82
foreach (DictionaryEntry De in food) {
83
Foodlist = Foodlist + "\n\n" + De.Key.ToString();
84
Foodlist = Foodlist + De.Value.ToString();
85
}
86
Console.WriteLine(Foodlist);
87
Console.WriteLine("---------------------");
88
Console.ReadLine();
89
}
90
}
91
public abstract class Builder {
92
/// <summary>
93
/// 建造者虚类,添加虚方法
94
/// </summary>
95
public abstract void BuilderHamb();
96
public abstract void BuilderCoke();
97
public abstract void BuilderChip();
98
public abstract void BuilderChicken();
99
public abstract Food GetFoods();
100
}
101
public class NormalBuilder : Builder {
102
private Food NormalFood = new Food();
103
public override void BuilderHamb()
104
{
105
NormalFood.add("Normal Hamb", "¥10.50");
106
}
107
public override void BuilderCoke()
108
{
109
NormalFood.add("Normal Coke", "¥7.00");
110
}
111
public override void BuilderChip()
112
{
113
NormalFood.add("FireChip", "¥7.00");
114
}
115
public override void BuilderChicken()
116
{
117
NormalFood.add("上校鸡块", "¥15.00");
118
}
119
public override Food GetFoods()
120
{
121
return NormalFood;
122
}
123
124
}
125
public class GoldBuilder : Builder {
126
private Food GoldFood = new Food();
127
public override void BuilderHamb()
128
{
129
GoldFood.add("Gold版 Hamb", "¥12.000");
130
}
131
public override void BuilderCoke()
132
{
133
GoldFood.add("Gold版 Coke", "¥8.00");
134
}
135
public override void BuilderChip()
136
{
137
GoldFood.add("Gold版FireChip", "¥8.00");
138
}
139
public override void BuilderChicken()
140
{
141
GoldFood.add("Gold版上校鸡块", "¥16.00");
142
}
143
public override Food GetFoods()
144
{
145
return GoldFood;
146
}
147
148
}
149
}

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

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149
