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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With