策略模式_C#_设计模式

abstract class Strategy
    {
        public abstract void IsStrategy();
    }
    class StrategyA : Strategy
    {
        public override void IsStrategy()
        {
            Console.WriteLine("IsStrategyA");
        }
    }
    class StrategyB : Strategy
    {
        public override void IsStrategy()
        {
            Console.WriteLine("IsStrategyA");
        }
    }
    class StrategyC : Strategy
    {
        public override void IsStrategy()
        {
            Console.WriteLine("IsStrategyA");
        }
    }
    class Context
    {
        Strategy strategy;
        public Context(Strategy strategy)
        {
            this.strategy = strategy;
        }
        public void ToContext()
        {
            strategy.IsStrategy();
        }
    }

       static void Main()   
        {
            Context context = new Context(new StrategyB());
            context.ToContext();
            Console.ReadKey();
        }
      
        
        
    

 

posted on 2013-08-13 00:11  staben  阅读(180)  评论(0)    收藏  举报

导航