In my C# program, I have a couple of interfaces of my own that I would want to keep internal to my assembly.
internal interface Doable {
void DoSomething ();
}
internal interface Informable {
void SomethingHappened (Doable obj);
}
And I have an abstract class as well that cannot be internal, and which abstractly implements the two interfaces like so.
public abstract class MyAbstractClass : Doable, Informable {
internal abstract void DoSomething ();
internal abstract void SomethingHappened (Doable obj);
// Other methods
}
When I do this, however, I get an error that MyAbstractClass does not implement Doable.DoSomething() (and SomethingHappened(Doable obj) as well).
I can change the access modifier of the abstractly implemented DoSomething() to public (which I don't want to in the first place, however), but then SomethingHappened(Doable obj) is a different matter: it complains (rightly so) that the interface Doable is internal (and thusly this method may not have the public access modifier).
I am in a dilemma. I basically want to keep both interfaces and all their concretely implemented methods across all classes in the assembly internal to it with external callers not being aware of their presence.
Wondering how to go about this?
public classwithinternal abstractmembers is a code smell. @Servy answer is a good one, another would be to exposepublic MyPublicAbstractClasswhich wrap (don't inherit!) someinternal MyInternalAbstractClass. - Sinatrinternalstuff (you do by using interface)? Why caller should know about it at all? Look at e.g. framework, I don't recall a class implementing some hidden interface like this, because design starts from creating public interfaces. And you are instead trying to create public class containing hidden stuff. Why? Because some hidden methods are using those hidden interfaces methods of public class or what? So you are trying to make that class performing two roles = code smell. Can you show us concrete code? It would be easier to argue and defend if your right. - Sinatr