[Lazarus] IUnknown and reference counting

Sven Barth pascaldragon at googlemail.com
Thu Mar 21 21:55:41 CET 2013


On 21.03.2013 21:48, Hans-Peter Diettrich wrote:
>>> Also the hype about CORBA interfaces looks like mere eye-candy or
>>> obfuscation to me. Delphi interfaces require neither COM nor CORBA, they
>>> are only open in either direction.
>>
>> But some people don't like the reference counting. They want to use
>> interfaces like in other languages to just define a "interface" to a
>> class.
>
> Since reference counting must be implemented, it also can be implemented
> as *not* counting references. Similar to AnsiString constants, which
> also live forever. A simple _AddRef after creation of an interfaced
> object achieves almost the same effect.

But then you need to implement these methods. Here I like CORBA style 
interfaces very much: just add the interface to any class, implement the 
methods the interface defines and be done. The same way as it is done in 
e.g. Java and C#.

And CORBA style interfaces also provide a bit more protection against 
using the implementation of the interface as they don't allow "as/is 
ClassType" like the COM style interfaces (they still allow "as 
InterfaceType/StringConstant" though if the interface has a string 
constant as a "GUID").

Regards,
Sven




More information about the Lazarus mailing list