我有一个定义的接口iClass
。接口中的一种方法将另一个接口iObject
作为参数。在另一个接口的实现中调用接口的特定子孙
在iClass
的一个具体实现中,我需要一个具体实现iObject
,ObjectImplementation
的方法 - 但C#告诉我需要按原样实现该方法。
这是为什么?是不是ObjectImplementation
iObject
的一个实例?我如何解决这个问题?我尝试使用抽象类,而我陷入了同样的混乱。
public interface iClass {
bool SomeMethod(iObject object);
}
public interface iObject {
... // some methods here
}
public ObjectImplementation : iObject {
... // some method implementations here
}
public ClassImplementation : iClass {
public bool SomeMethod(ObjectImplementation object) // <- C# compiler yells at me
{
}
}
这如果'ClassImplementation'中的'SomeMethod'的实现确实需要一个'ObjectImplementation'而不需要其他东西,那么这个方法将不起作用。例如。因为'ObjectImplementation'具有额外的成员。 – 2013-05-14 07:32:54