public interface IParent
{
void ParentMethod();
}
public interface IOne : IParent
{
void OneMethod();
}
public interface ITwo : IParent
{
void TwoMethod();
}
public class SomeClass : IOne, ITwo
{
...
}
Attempting to declare ParentMethod explicitly as a member of IOne fails to compile as not a member of IOne, e.g.
"void IOne.ParentMethod()" within SomeClass will not compile whereas void IOne.OneMethod is fine.
This behaves as expected when instantiating a SomeClass object and using it via the interfaces
SomeClass oSomeClass = new SomeClass();
IOne iOne = (IOne) oSomeClass;
ITwo iTwo = (ITwo) oSomeClass;
IParent iParent = (IParent) oSomeClass;
iOne.OneMethod();
iOne.ParentMethod();
iTwo.TwoMethod();
iTwo.ParentMethod();
iParent.ParentMethod();
FootNote 1: I did subsequently find some related information in the C# language specification
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_13.asp), including
my favorite section to date in 13.1.2: "The base interfaces of an interface are the explicit base interfaces and
their base interfaces. In other words, the set of base interfaces is the complete transitive closure of the
explicit base interfaces, their explicit base interfaces, and so on." Hmmm, is my case a complete or a partial
transitive closure? Being more of a practitioner and less of an academecian these days, I read on... Section 13.2.5 is more germaine, dealing with more complex cases than what I had. It implicitly clarified my argualbly more common case. Isn't dot Net fun?
No comments:
Post a Comment