Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent accessibility: base class is less accessible than class

So I have an abstract base class in a DLL and child classes of that class. I want the childs to be public, but the base to be private so that it cannot be accessed outside of the dll.

How do I do that?

like image 397
Ivan Prodanov Avatar asked Nov 07 '12 13:11

Ivan Prodanov


2 Answers

You don't and you can't.

If you want to expose the class as public, the base-type must be public. One other option is to have a public interface, and only expose the type via the interface (presumably with a factory method somewhere for creating instances).

One final option is to encapsulate the base-class rather than inherit it.

like image 113
Marc Gravell Avatar answered Oct 22 '22 07:10

Marc Gravell


Make it public, make all constructors internal (if you're using the default constructor, add a parameterless constructor to override that).

Then while public and not sealed, it can't be sub-classed by external code.

like image 20
Jon Hanna Avatar answered Oct 22 '22 07:10

Jon Hanna