Why not inherit from List?

前端 未结 27 1769
悲哀的现实
悲哀的现实 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:21

    When is it acceptable?

    To quote Eric Lippert:

    When you're building a mechanism that extends the List mechanism.

    For example, you are tired of the absence of the AddRange method in IList:

    public interface IMoreConvenientListInterface : IList
    {
        void AddRange(IEnumerable collection);
    }
    
    public class MoreConvenientList : List, IMoreConvenientListInterface { }
    

提交回复
热议问题