Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

inheritance

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

C++

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

C#

  public abstract NServlet class : private System.Web.UI.Page {     // error "type expected" }  

I am implementing a "servlet like" concept in an .aspx page and I don't want the concrete class to have the ability to see the internals of the System.Web.UI.Page base.

like image 206
mmattax Avatar asked Aug 28 '08 19:08

mmattax


People also ask

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.


1 Answers

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.

like image 133
Brian Stewart Avatar answered Oct 06 '22 22:10

Brian Stewart