I am creating an interface. Lets say the following
internal interface MyInterface
{
string Prop { get; }
}
This is an internal interface. I indent to use this within the project and do not want to expose Prop
publicly. However when I try to implement this interface into a class, I am forced to make the Prop
property public. I do not understand why I need to make this property public when the interface itself is internal and can only be used internally.
Because an interface itself is only a contract of public-facing functionality for an object. Anything non-public doesn't really belong there, but could instead go on the implementing type.
It's essentially a non-issue, however. If the type is internal
, then any properties on the type aren't visible outside of that scope. Because how could they be? The type itself isn't known outside of that scope. (Any code which doesn't know what MyInterface
is certainly isn't going to know what MyInterface.Prop
is.)
The properties are public
in the sense that consuming code can see them. But this only matters to code which can consume that type in the first place, which is only internal
to that assembly.