设计模式之美:Builder(生成器)(三)

2014-11-24 00:57:58 · 作者: · 浏览: 5
66 return _complexProduct.ValueDependOnFortune;
67 }
68 }
69
70 public class GoodWeatherAndGoodLuckDirector
71 {
72 public void ConstructWithGoodWeatherAndGoodLuck(AbstractComplexProductBuilder builder)
73 {
74 string weather = builder.BuildValueDependOnWeatherPart(@"PM2.5 < 50");
75 builder.BuildValueDependOnFortunePart(@"Good Luck", weather);
76 }
77
78 public void ConstructWithBadWeatherAndBadLuck(AbstractComplexProductBuilder builder)
79 {
80 string weather = builder.BuildValueDependOnWeatherPart(@"PM2.5 > 500");
81 builder.BuildValueDependOnFortunePart(@"Bad Luck", weather);
82 }
83 }
84
85 public class Client
86 {
87 public void TestCase2()
88 {
89 AbstractComplexProductBuilder builder = new ConcreteProductBuilderA("Sunday", 9);
90 GoodWeatherAndGoodLuckDirector director = new GoodWeatherAndGoodLuckDirector();
91
92 builder.BeginBuild();
93 director.ConstructWithGoodWeatherAndGoodLuck(builder);
94 ComplexProduct productWithGoodLuck = builder.EndBuild();
95
96 builder.BeginBuild();
97 director.ConstructWithBadWeatherAndBadLuck(builder);
98 ComplexProduct productWithBadLuck = builder.EndBuild();
99 }
100 }
101 }