0

Why in every ICRUD implementation should I instantiate the IINTERFACE interface methods?

type ICRUD<t> = interface
  ['{2CA41589-BEEC-4640-8E18-B2A35ECF1B2D}']
  function Create(obj: t):t;
  function Read(obj: t):t;
  function Update(obj: t):t;
  function Delete(obj: t):t;
end;

type
  TCliente = class(TPersona, ICRUD<TCliente>)
 private
  function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
  function _AddRef: Integer; stdcall;
  function _Release: Integer; stdcall;
 public
  constructor Crear;
  function Create(Cliente: TCliente):TCliente;
  function Read(Cliente: TCliente):TCliente;
  function Update(Cliente: TCliente):TCliente;
  function Delete(Cliente: TCliente):TCliente;
end;

for every ICRUD implementation the compiler forces me to implement those methods. Is it mandatory? I use delphi 10

jmontegrosso
  • 89
  • 1
  • 11
  • 3
    You can chose to derive your class from [`TInterfacedObject`](http://docwiki.embarcadero.com/Libraries/Sydney/en/System.TInterfacedObject) to get these for free. – Andreas Rejbrand May 07 '21 at 12:37
  • 3
    Why? Because all interfaces derive from `IInterface`. Is it mandatory to implement these? Yes. – David Heffernan May 07 '21 at 13:04
  • Perfect then you have to inherit the class from TInterfacedObject so that this does not happen. Thank you very much! – jmontegrosso May 07 '21 at 17:24

0 Answers0