5

I have the following interface:

type IDataAccessObject<Pk; T:class> = interface
   getByPrimaryKey(key: PK) : T;
   //... more methods
end;

And an implementation of the interface as follows:

type TMyClassDAO = class(TInterfacedObject, IDataAccessObject<integer, TMyClass>)
   getByPrimaryKey(key:integer) : TMyClass;
   // more methods
end;

Note that I am not providing a guid for the interface (because every instantiation of the previous generic interface is a different interface and they should not share the same guid). However I am not sure whether that does not break reference counting implemented by TInterfacedObject?

BigONotation
  • 4,406
  • 5
  • 43
  • 72
  • 1
    See also [Are GUIDs necessary to use interfaces in Delphi?](https://stackoverflow.com/q/2992183/576719). – LU RD May 25 '17 at 13:33

1 Answers1

15

Reference counting does not rely on a GUID, but on _AddRef() and _Release() method implementations.

Since you inherit from TInterfacedObject, reference counting will work for all of your object instances.

The only thing you lose if you don't provide a GUID is the ability to query one interface from another, such as in calls to the Supports() function, QueryInterface() interface method, and the is and as operators.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159