I feel like this question may be off topic as subjective, but I'm curious.
In java I'm used to using package private and public to hide the implementation of types from other packages. I usually have an interface
such as:
public interface IMyClass {
...
}
Any common functionality of IMyClass
implementations are then defined in a private abstract class
within the same package
abstract class AMyClass implements IMyClass {
public AMyClass(...)
...
}
Then the derived types are public
and are also defined in the IMyClass
package
public class CustomMyClass extends AMyClass {
public CustomMyClass(...){
super(...)
...
}
In c# I would like to follow the same structure, but when you extend an abstract class
it has to be public
. The only thing I could find to prevent other packages from extending AMyClass
or using its internal functions was to make their access level internal
.
public interface IMyClass{
...
}
...
public class AMyClass : IMyClass {
internal AMyClass(...)
...
}
...
public class CustomMyClass : AMyClass {
public CustomMyClass(...) : base(...){
...
}
But this style still allows other c# projects 2 ways to group the subclasses, AMyClass
or IMyClass
types. This seems really sloppy, especially if I want to create another abstract
base class for different types of IMyClass
. In that case there would now be 2 abstract classes exposed that I don't want other projects to use.
Is there a way to prevent other projects from using the abstract classes, or is it simply something to put in the projects documentation and rely on an honor system of sorts?