public static void Run() { var strategy1 = new ConcreteStrategy1(); var strategy2 = new ConcreteStrategy2(); var context = new Context(); context.SetStrategy(strategy1); context.DoSomething("doing something..."); context.SetStrategy(strategy2); context.DoSomething("doing something..."); }
public static void Main_Strategy() { var context = new SContext(); //定义算法 var cs1 = new ConcreteStrategy1(); var cs2 = new ConcreteStrategy2(); // context.SetStrategy(cs1); context.RunAlgorithm(); context.SetStrategy(cs2); context.RunAlgorithm(); Console.ReadLine(); }