示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("--------------------StrategyPattern--------------------");
            Console.WriteLine();
            Strategy strategyA = new ConcreteStrategyA();
            Strategy strategyB = new ConcreteStrategyB();
            Strategy strategyC = new ConcreteStrategyC();
            var      context   = new Context(strategyA);

            context.GetResult();
            context.Strategy = strategyB;
            context.GetResult();
            context.Strategy = strategyC;
            context.GetResult();

            Console.ReadKey();
        }
        public static void Main(string[] args)
        {
            Strategy strategyA = new ConcreteStrategyA();
            Strategy strategyB = new ConcreteStrategyB();
            Strategy strategyC = new ConcreteStrategyC();

            Context context = new Context(strategyA);

            context.AlgorithmImplement();

            context = new Context(strategyB);
            context.AlgorithmImplement();

            context = new Context(strategyC);
            context.AlgorithmImplement();

            Console.Read();
        }