我有一個定義的接口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