Does C# have the notion of private and protected inheritance?

前端 未结 10 1063
执笔经年
执笔经年 2020-12-16 09:02

Does C# have the notion of private / protected inheritance, and if not, why?

C++


class Foo : private Bar {
 public:
   ...
 }; 
         


        
10条回答
  •  庸人自扰
    2020-12-16 09:49

    C# allows public inheritance only. C++ allowed all three kinds. Public inheritance implied an "IS-A" type of relationship, and private inheritance implied a "Is-Implemented-In-Terms-Of" kind of relationship. Since layering (or composition) accomplished this in an arguably simpler fashion, private inheritance was only used when absolutely required by protected members or virtual functions required it - according to Scott Meyers in Effective C++, Item 42.

    My guess would be that the authors of C# did not feel this additional method of implementing one class in terms of another was necessary.

提交回复
热议问题