[Kde-pim] Re: KCalCore + Observers

Ingo Klöcker kloecker at kde.org
Tue May 3 19:50:24 BST 2011


On Tuesday 03 May 2011, Patrick Ohly wrote:
> Hello!
> 
> KCalCore uses observers to notify library users of changes. These are
> defined as abstract base classes with a few virtual methods:
> 
> class KCALCORE_EXPORT RecurrenceRule
> {
>   public:
>     class RuleObserver
>     {
>       public:
>         virtual ~RuleObserver();
>         /** This method is called on each change of the recurrence
> object */
>         virtual void recurrenceChanged( RecurrenceRule * ) = 0;
>     };
> ...
> 
> Similar for Calendar::CalendarObserver.
> 
> Have you considered changing this to the signal/slot mechanism? It
> has pros and cons, of course, I just want to get a feeling for your
> opinions.
> 
> The advantage is that it'll be possible to extend the API without
> breaking the ABI.

What API do you want to extend? That of RuleObserver? I doubt that its 
extremely slim API is supposed to be extended. Moreover, it's easy to 
write a convenience class with a richer interface implementing the 
RuleObserver interface (probably via a private implementation of 
recurrenceChanged() to prevent further reimplementation).


> It would also fit better into apps which are already using QObject.
> 
> The disadvantage is that the observer classes can be used in apps
> which do not use QObject.
> 
> A possible compromise is this:
>       * Switch libkcalcore to the signal/slot version of the API,
>         removing the register/removeObserver() calls and these
> Observer base classes. Requires adding QObject as base class of some
> classes (ReccurenceRule).
>       * Add a second library which offers the Observer style API,
>         implemented by connecting the signals in libkcalcore to slots
> in the observers. Its ABI would break if future changes are needed.

If you prefer connecting to signals instead of implementing the observer 
interface then you could implement a QObject-derived 
SignalingRuleObserver which works internally as observer (e.g. by 
implementing recurrenceChanged()) and externally as signal-emitting 
QObject (with a special connect() method which does the registration and 
the connection of your slot).


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20110503/acb73587/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list