[IGSTK-Developers] Observer/Observable pattern
Luis Ibanez
luis.ibanez at kitware.com
Fri Feb 23 18:34:56 EST 2007
Hi Ziv,
The Observer pattern in ITK was mostly copied from
the functionality existing in VTK at the time.
The relationship between Observers and Observables
is a many-to-many relationship. That is, and ITK
object may have many Observers connected, and a
given Observer may be observing many different
objects.
When an event is invoked, the Execute method of
the observer is called. This method include as
first argument a pointer to the "caller", which
is a pointer to an itkObject.
Observable objects *ARE NOT* responsible for the
observer memory, not the other way around.
What you point out, is rather a weakness in the
implementation since the observables are assuming
that the observers are still alive by the time the
observable invokes an event. This may actually be
considered a bug...
So,.. there are two independent issues:
1) Can Observers observe multiple object ?
The answer is YES.
2) Why do observables use a list of raw
pointers instead of SmartPointers ?
The answer is : This can be considered a bug.
(or at least a weakness...)
The fact that (2) uses raw pointers shouldn't be
considered as an indication of (1).
Regards,
Luis
===================
Ziv Yaniv wrote:
> Hi All,
>
> The following question is with regard to ITK, but it spills over to
> IGSTK, so I'm sending it to this development list as I'm not on the ITK
> developers one.
>
> I would like to understand the reasoning behind the design of the
> ITK observer/observable pattern implementation. According to the
> documentation of the AddObserver() method in itk::Object I cannot
> have the same Observer attached to several objects, as observable
> objects are responsible for the observer's memory. This is
> reflected in the use of a raw pointer to a itk::Command object in
> the itk::Object::AddObserver() method.
>
> In the spirit of ITK I expected the AddObserver method to receive
> a SmartPointer which also allows a single observer
> attached to multiple objects, as the memory would be released
> when the last observable deleted its observers.
>
> Am I missing something? Should this go into a bug/feature request on
> the ITK side?
>
> regards
> Ziv
> _______________________________________________
> IGSTK-Developers mailing list
> IGSTK-Developers at public.kitware.com
> http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-developers
>
More information about the IGSTK-Developers
mailing list