File tree Expand file tree Collapse file tree
DesignPatterns/StrategyPattern/StrategyPattern Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,16 @@ class Program
1010 {
1111 static void Main ( string [ ] args )
1212 {
13+ Context context ;
14+ context = new Context ( new ConcreteStrategyA ( ) ) ;
15+ context . ContextOperation ( ) ;
16+
17+ context = new Context ( new ConcreteStrategyB ( ) ) ;
18+ context . ContextOperation ( ) ;
19+
20+ context = new Context ( new ConcreteStrategyC ( ) ) ;
21+ context . ContextOperation ( ) ;
22+
1323 }
1424 }
1525}
Original file line number Diff line number Diff line change @@ -31,4 +31,29 @@ public void ContextOperation()
3131 this . strategy . Algorithm ( ) ;
3232 }
3333 }
34+
35+
36+ class ConcreteStrategyA : Strategy
37+ {
38+ public override void Algorithm ( )
39+ {
40+ Console . WriteLine ( "算法A" ) ;
41+ }
42+ }
43+
44+ class ConcreteStrategyB : Strategy
45+ {
46+ public override void Algorithm ( )
47+ {
48+ Console . WriteLine ( "算法B" ) ;
49+ }
50+ }
51+
52+ class ConcreteStrategyC : Strategy
53+ {
54+ public override void Algorithm ( )
55+ {
56+ Console . WriteLine ( "算法C" ) ;
57+ }
58+ }
3459}
You can’t perform that action at this time.
0 commit comments