[Lazarus] IUnknown and reference counting

Graeme Geldenhuys graeme at geldenhuys.co.uk
Thu Mar 21 15:06:35 CET 2013


On 2013-03-21 13:42, Michael Schnell wrote:
>> * the ability to delegate the implementation of the interface to a 
>> different class (using the "implements" keyword)
> To allow for a kind of multiple inheritance, I supple.

No, not at all. It is to reuse existing code. You can have one class
(say TObserver) that implements a IObserver interface, and that is all
that that class does. You can then use the "implements" keyword in
another class (eg: TMyObject), and delegate the IObserver implementation
to the TObserver class. No need for the TMyObject class to re-implement
all the methods that IObserver specifies.

This concept is extremely handy if you implement something like
Model-View-Controller (MVP) in Object Pascal and make use of Interfaces.
Joanna Carter wrote some articles many years back on implementing MVP
using Delphi. She used interfaces and delegation extensively (the most I
have ever seen in any code). You can Google her name to find the articles.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list