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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to