Why not inherit from List?

前端 未结 27 1756
悲哀的现实
悲哀的现实 2020-11-21 05:39

When planning out my programs, I often start with a chain of thought like so:

A football team is just a list of football players. Therefore, I should

27条回答
  •  花落未央
    2020-11-21 06:17

    A football team is not a list of football players. A football team is composed of a list of football players!

    This is logically wrong:

    class FootballTeam : List 
    { 
        public string TeamName; 
        public int RunningTotal 
    }
    

    and this is correct:

    class FootballTeam 
    { 
        public List players
        public string TeamName; 
        public int RunningTotal 
    }
    

提交回复
热议问题