this is an issue ive been faced with countless number of times.. consider..
[public/private] interface IBase
{
void DoCore();
}
public interface IDerived_A : IBase
{
void Do_A();
}
public interface IDerived_B : IBase
{
void Do_B();
}
here i have 2 useful interfaces that provide some common functionality (provided by the IBase interface), plus some other functionality unique to either of them.. c# forces me to declare IBase as public (the same visibility as the inheriting interfaces).. however, the IBase interface is visible to everyone.. there is no need for anyone else to use this interface.. ppl only need to access the IDeriver_X interfaces.. how can i hide the IBase interface from the users of my code? there can be two kinds of users of my code..
- code in the same namespace / assembly accessing IDerived_X..
- code in a separate project referencing the assembly containing IDeriver_X..
ps.. i hate making more interfaces public than is neccessary (neccessary means only those interfaces that ppl will use directly).. ps2.. i face the same dilemma with classes..
EDIT:
i have a feeling that the question was misinterpreted a bit.. for that im posting a clarification.. the issue isnt just related to interfaces.. it bugs me about classes too.. consider the following code..
public abstract class Vehicle
{
// generic vehicle functionality
}
public Car : Vehicle
{
// functionality specific to cars
}
public Truck : Vehicle
{
// functionality specific to trucks
}
Car and Truck are the ONLY two kinds of objects im allowing the users of my code to use.. to make my job easier, and to avoid dupilcation of code, ive moved the common code to the Vehicle abstract class.. but that doesnt mean its ok for the user to store references to cars or trucks in vehicle variables.. from the perspective of the users, my code should only expose cars and trucks (and not vehicles or engines or whatever base classes i used internally to avoid code duplication).. specifically, im looking for a technique that allows me to expose complete cars and trucks but not any other incomplete building blocks like vehicles or engines.. the problem is, c# doesnt let me make the base classes private if the derived class is public.. does that make more sense? =)