我正在尝试声明要从中继承的接口的自定义列表,以获取特定接口的列表(我知道 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;
TSpecificInterfaceList 不会编译:
E2211 “GetFirst”声明与接口“ISpecificInterfaceList”中的声明不同
我想我理论上可以使用 TCustomInterfaceList 但我不想每次使用它时都必须投射“GetFirst”。我的目标是拥有一个既继承基类的行为又包装“GetFirst”的特定类。
我怎样才能做到这一点?
谢谢!