zoukankan      html  css  js  c++  java
  • 策略模式实例

    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();
    
             
            }
    

      

     

      

      

  • 相关阅读:
    方法中的散列可变参数
    方法中的散列可变参数
    策略模式
    策略模式
    HashSet,TreeSet
    HashSet,TreeSet
    ArrayList和LinkedList
    ArrayList和LinkedList
    关于鼠标悬浮标签元素效果(CSS:cursor属性)
    关于鼠标悬浮标签元素效果(CSS:cursor属性)
  • 原文地址:https://www.cnblogs.com/lijianhua/p/5735047.html
Copyright © 2011-2022 走看看