是否可以使用接口变量在接口中未定义的接口的实现类中调用方法,如下所示:
interface ILookup {
public void someInterfaceMethod1();
public void someInterfaceMethod2();
}
...和实现类:
public class extendedLookUpImplementor: ILookup
{
//constructor
LookUpImplementor(){
}
public void someInterfaceMethod1(){
// Implementation Code here.
}
public void someInterfaceMethod2(){
// Implementation Code here.
}
public void ExtendedMethod(){
// Implementation Code here.
}
}
在客户端代码中:
ILookup lookupVar = new LookUpImplementor();
lookupVar -> someInterfaceMethod1(); // i know it will work.
lookupVar -> someInterfaceMethod2(); // i know it will work.
我的问题是,我可以使用如下所示的 lookupVar 调用 ExtendedMethod:
lookupVar -> ExtendedMethod(); // Note again that ExtendedMethod() is not defined in Ilookup interface/contract.