我试图声明一个自定义的接口列表,我想继承它以获取特定接口的列表(我知道IInterfaceList,这只是一个例子).我正在使用Delphi 2007,因此我无法访问实际的泛型(可惜我).
这是一个简化的例子:
ICustomInterfaceList = interface
procedure Add(AInterface: IInterface);
function GetFirst: IInterface;
end;
TCustomInterfaceList = class(TInterfacedObject, ICustomInterfaceList)
public
procedure Add(AInterface: IInterface);
function GetFirst: IInterface;
end;
ISpecificInterface = interface(IInterface)
end;
ISpecificInterfaceList = interface(ICustomInterfaceList)
function GetFirst: ISpecificInterface;
end;
TSpecificInterfaceList = class(TCustomInterfaceList, ISpecificInterfaceList)
public
function GetFirst: ISpecificInterface;
end;
Run Code Online (Sandbox Code Playgroud)
TSpecificInterfaceList将无法编译:
E2211'GetFirst'声明与接口'ISpecificInterfaceList'中的声明不同
我想我理论上可以使用TCustomInterfaceList,但我不想每次使用时都要使用"GetFirst".我的目标是拥有一个特定的类,它继承基类的行为并包装"GetFirst".
我怎样才能做到这一点?
谢谢!
我有必要向ServiceStack的JsonServiceClient.Get提供IReturn或IReturnVoid引用吗?必须有一个很好的理由(我对框架很新)但我不明白为什么我必须将我的对象转换为IReturn包装器或使它们依赖于ServiceStack.
我已阅读这些帖子,但找不到我正在寻找的解释(仅解决方法):
谢谢!