Is Inheritance really needed?

后端 未结 22 2143
孤街浪徒
孤街浪徒 2020-12-14 00:20

I must confess I\'m somewhat of an OOP skeptic. Bad pedagogical and laboral experiences with object orientation didn\'t help. So I converted into a fervent believer in Visua

22条回答
  •  青春惊慌失措
    2020-12-14 01:05

    In the following, inheritance is used to present a particular property for all of several specific incarnations of the same type thing. In this case, the GeneralPresenation has a properties that are relevant to all "presentation" (the data passed to an MVC view). The Master Page is the only thing using it and expects a GeneralPresentation, though the specific views expect more info, tailored to their needs.

       public abstract class GeneralPresentation
        {
            public GeneralPresentation()
            {
                MenuPages = new List();
            }
            public IEnumerable MenuPages { get; set; }
            public string Title { get; set; }
        }
    
        public class IndexPresentation : GeneralPresentation
        {
            public IndexPresentation() { IndexPage = new Page(); }
            public Page IndexPage { get; set; }
        }
    
        public class InsertPresentation : GeneralPresentation
        {
            public InsertPresentation() { 
              InsertPage = new Page(); 
              ValidationInfo = new PageValidationInfo(); 
            }
            public PageValidationInfo ValidationInfo { get; set; }
            public Page InsertPage { get; set; }
        }
    

提交回复
热议问题