码迷,mamicode.com
首页 > 其他好文 > 详细

策略模式实例

时间:2016-08-04 01:15:00      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

public interface ITurn
    {
       string GetUrl();
    }
 public class NatiuBase:ITurn
    {
        public string StartDate { get; set; }
        public string EndDate { get; set; }
        public string PDUId { get; set; }
        public string Type { get; set; }

        public NatiuBase(string startDate,string endDate,string pduId,string type)
        {
            this.StartDate = startDate;
            this.EndDate = endDate;
            this.PDUId = pduId;
            this.Type = type;
        }

        public virtual string GetUrl()
        {
            return "我是父类";
        }

      


    }
public class KDS:NatiuBase
    {
        public KDS(string startDate, string endDate, string pduId, string type): base(startDate, endDate, pduId, type)
        { }
        public override string GetUrl()
        {
            return string.Format("开始日期:{0},结束日期{1}", StartDate, EndDate);
        }
    }

public class Context
    {
        public ITurn iturn;
        public Context(ITurn iturn)
        {
            this.iturn = iturn;
        }

        public string GetUrl()
        {
            return iturn.GetUrl();
        }
    }

 

 static void Main(string[] args)
        {
            Context context = new Context(new KDS("2012-02-12", "2012-09-12", "50000", "kds_all"));
            Console.WriteLine(context.GetUrl());

            Context context2 = new Context(new NatiuBase("2012-02-12", "2012-09-12", "50000", "kds_all"));
            Console.WriteLine(context2.GetUrl());
            Console.ReadKey();

         
        }

  

 

  

  

策略模式实例

标签:

原文地址:http://www.cnblogs.com/lijianhua/p/5735047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!