Embarcadero Delphi Interfaces Inheritance for interfaces


Example

Interfaces can inherit from each other, exactly like classes do, too. An implementing class thus has to implement functions of the interface and all base interfaces. This way, however, the compiler doesn't know that the implenting class also implements the base interface, it only knows of the interfaces that are explicitly listed. That's why using as ISuperInterface on TImplementer wouldn't work. That also results in the common practice, to explicitly implement all base interfaces, too (in this case TImplementer = class(TInterfacedObject, IDescendantInterface, ISuperInterface)).

ISuperInterface = interface
    ['{A2437023-7606-4551-8D5A-1709212254AF}']
    procedure Method1();
    function Method2(): Boolean;
end;

IDescendantInterface = interface(ISuperInterface)
    ['{6C47FF48-3943-4B53-8D5D-537F4A0DEC0D}']
    procedure SetValue(const aValue: TObject);
    function  GetValue(): TObject;

    property Value: TObject read GetValue write SetValue;
end;

TImplementer = class(TInterfacedObject, IDescendantInterface)
    // ISuperInterface
    procedure Method1();
    function Method2(): Boolean;

    // IDescendantInterface
    procedure SetValue(const aValue: TObject);
    function  GetValue(): TObject

    property Value: TObject read GetValue write SetValue;
end;