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