1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5:
6: namespace StrategyPattern
7: { 8: public interface IStrategy
9: { 10: int StrategyMethod(int demoArg);
11: }
12:
13: public class ConcreteStrategyA : IStrategy
14: { 15: public int StrategyMethod(int demoArg)
16: { 17: return demoArg;
18: }
19: }
20:
21: public class ConcreteStratgegyB : IStrategy
22: { 23: public int StrategyMethod(int demoArg)
24: { 25: return demoArg * 2;
26: }
27: }
28:
29: public class ContextClass
30: { 31: // Helper
32: public bool addStrategy(IStrategy strategy)
33: { 34: if (this.numberOfStrategies < MAX_STRATEGIES)
35: { 36: strategies[this.numberOfStrategies] = strategy;
37: this.numberOfStrategies++;
38: return true;
39: }
40: else return false;
41: }
42:
43: // Fields
44: private static int MAX_STRATEGIES = 5;
45: private int numberOfStrategies = 0;
46: private IStrategy[] strategies = new IStrategy[MAX_STRATEGIES];
47: }
48: }