How to keep base class methods private in a derived class

I am writing an API (C# class library) to distribute to users of my product. I derive this class (derived.cs) from a base class (base.cs) so that it is a wapper for the base class so that the base class is hidden. I have declared the methods in the base class as protected so that my derived class can have access to them. However, when using the the resulting .dll as a reference in another application the name of the base class, plus all of its protected methods are exposed (in the object viewer). I have also tried to declare the base class as protected, but apparently this is not allowed.

I would prefer that my customers not be able to see the base class protected methods. How can I hide the name & methods of the base class



Answer this question

How to keep base class methods private in a derived class

  • Randal Greene

    It sounds like you are not having more than one class inherit from your base class...if that is the case, why not just put everything in one class and anything you don't want visible you can make private

  • DmitryMS

    OOP doesn't allow this.

  • Armin Prosch

    JD,

    if your base class and your derived class are in the same class library you can declare the methods of the base class "internal".

    That is actually what I did, and I could still see the "internal protected" methods in the object viewer of the app that referenced the class library (.dll).


  • EthanS

    OOP might not, but C# might - if your base class and your derived class are in the same class library you can declare the methods of the base class "internal".
    The result will be that these methods can be used only inside the class library, but another application referencing the dll will not have access to these methods (not even see them/not even via reflection). It will of course not work anymore if "derived.cs" itself is referencing "base.cs" from another dll...


  • zolivier

    Well...I did consider doing that, and may still. However, in the true spirit of OOP I would like to keep this functionality seperate. In fact, later I may write another derived class that derives from the original base class.

    Thanks for the comments....


  • How to keep base class methods private in a derived class