设计模式一:策略模式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StrategyTest
{
    class ZhaoYun
    {
        static void Main(string[] args)
        {
            Context context;
            context = new Context(new Green());
            context.Operate();

            Console.Read();
        }
    }

    
    public interface IStrategy
    {

         void Operate();
    }


    class Red:IStrategy
    {
        
        public void Operate()
        {
            Console.WriteLine("Open the Red Strategy:zou hou men ");
        }
    }

    class Green:IStrategy
    {

        public void Operate()
        {
            Console.WriteLine("Open the Red Strategy:zu ji zhui bing");
        }
    }

    class Context
    {
        private IStrategy strategy;

        public  Context(IStrategy s)
        {
            this.strategy = s;
        }

        public void Operate()
        {
            this.strategy.Operate();
        }
    }
}

 

posted on 2013-06-24 08:32  中子持心  阅读(124)  评论(0编辑  收藏  举报

导航