A
Anders Borum
Hello!
I was wondering why we're allowed to define interfaces as internal, when all
the members of the interface, when implemented in a class, are made public?
I know that interfaces serve as contracts, but why wouldn't you be allowed
to have internal contracts also, not necessarily exposing the members
publicly? You're not allowed to cast an object to the internal interface,
but I'm unable to keep the members internal.
It's quite annoying as I'll have to introduce extra abstract classes to
achieve the hidden interface members.
internal interface IXml
{
string ToXml();
}
public class CmsObject : IXml
{
.. other members / constructors
public string ToXml() { return null; }
}
... and in another project (assembly):
CmsObject o = new CmsObject();
string s = o.ToXml();
I was wondering why we're allowed to define interfaces as internal, when all
the members of the interface, when implemented in a class, are made public?
I know that interfaces serve as contracts, but why wouldn't you be allowed
to have internal contracts also, not necessarily exposing the members
publicly? You're not allowed to cast an object to the internal interface,
but I'm unable to keep the members internal.
It's quite annoying as I'll have to introduce extra abstract classes to
achieve the hidden interface members.
internal interface IXml
{
string ToXml();
}
public class CmsObject : IXml
{
.. other members / constructors
public string ToXml() { return null; }
}
... and in another project (assembly):
CmsObject o = new CmsObject();
string s = o.ToXml();