File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
DesignPatterns/StrategyPattern/StrategyPattern Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,26 @@ public ProduceContext(ProduceStrategy ps)
4141 this . produceStrategy = ps ;
4242 }
4343
44+ /// <summary>
45+ /// 加入简单工厂模式
46+ /// </summary>
47+ /// <param name="i"></param>
48+ public ProduceContext ( int i )
49+ {
50+ switch ( i )
51+ {
52+ case 1 :
53+ produceStrategy = new ProduceStrategySummer ( ) ;
54+ break ;
55+ case 2 :
56+ produceStrategy = new ProduceStrategyWinter ( ) ;
57+ break ;
58+ default :
59+ Console . WriteLine ( "没有此种策略" ) ;
60+ break ;
61+ }
62+ }
63+
4464 public void GetDecision ( int cap )
4565 {
4666 produceStrategy . Decision ( cap ) ;
Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ static void Main(string[] args)
2626
2727 produceContext = new ProduceContext ( new ProduceStrategyWinter ( ) ) ;
2828 produceContext . GetDecision ( 1 ) ;
29+
30+ ProduceContext ps = new ProduceContext ( 1 ) ;
31+ ps . GetDecision ( 1 ) ;
32+
33+ ps = new ProduceContext ( 2 ) ;
34+ ps . GetDecision ( 1 ) ;
35+
2936 }
3037 }
3138}
You can’t perform that action at this time.
0 commit comments