I was wondering if there is a way to do the following:
In my project, I defined an interface, say IFruit. This interface has the public method GetName (). I also declare an IApple interface that implements IFruit and provides another method like GetAppleType () or something else. Eat more fruits like Ibanana, Jerry, whatever.
Now outside, I only want to be able to use the actual implementation of the fruit, not IFruit itself. But I canβt declare the IFruit interface private or internal, since the inherited interfaces will say: "Cannot be implemented because the base class is less accessible."
I know this is possible with abstract implementations, but this is not an option in this case: I really need to use interfaces. Is there such an option?
Update I think my example needs clarification :) I use MEF to load interface implementations. Downloaded collections are based on IApple, IBanana, ICherry, etc. But IFruit itself is useless; I cannot use classes based only on this interface. Therefore, I was looking for a way to prevent other developers from implementing exclusively IFruit, believing that their class will be loaded (which will not). So basically it comes down to:
internal interface IFruit { public string GetName(); }
public interface IApple : IFruit { public decimal GetDiameter(); }
public interface IBanana : IFruit { public decimal GetLenght(); }
But this does not compile due to the less accessible base interface.
Jasper
source share