[fpc-pascal] Explicit Interface implementation and inheritance

Dmitry Boyarintsev skalogryz.lists at gmail.com
Sun Aug 15 00:43:00 CEST 2021


Hello,

Why is interface implementation not inherited, if explicit implementation
is used.

Example.

Here are interfaces:
  IAAA = interface
    procedure MethodA;
  end;
  IBBB = interface(IAAA)
    procedure MethodB;
  end;

Interface IBBB inherits from IAAA

Here's an implicit interface implementation:

  TObjA = class(TInterfacedObject, IAAA)
    procedure MethodA;
  end;

  TObjB = class(TObjA, IBBB)
    procedure MethodB;
  end;

Class TObjB inherits from TObjA. Where TObjA implements IAAA.
And so TObjB only needs to implement MethodB, and MethodA is implicitly
mapped for the interface method.

Here's an explicit interface implementation:

  TImpA = class(TInterfacedObject, IAAA)
  public
    procedure CallOfA; virtual;
    procedure IAAA.MethodA = CAllOfA;
  end;

  // compiler error. No matching implementation for interface method
"MethodA"; found
  TImpB = class(TImpA, IBBB)
  public
    procedure CallOfB;
    procedure IBBB.MethodB = CallOfB;
  end;

Why is it happening? TImpB inherites from TImpA. In TImpA the MethodA is
implemented by "CallOfA".

Is it a requirement to map all the methods of implemented interfaces? (no
matter if they were implemented in parent classes).

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210814/21f440b4/attachment.htm>


More information about the fpc-pascal mailing list