Boost logo

Boost Users :

From: Asif Lodhi (asif.lodhi_at_[hidden])
Date: 2008-03-29 17:53:25


Hi Steven,

On 3/29/08, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> X.................................
> Using both a function and a variable is redundant. Either have a
> virtual function that can be overridden to specify the ID or a
> constructor parameter and a variable. Not both.

Yes. It was a mistake - I scribbled the whole thing very hurriedly.

> There are already function pointers in Boost.Signals. I'm pretty sure
> that this observer
> requires either the use of global signals (Yuck) or a cyclic visitor
> (Also not nice).
> Using a map achieves the same effect, keeping the dispatching logic
> cleanly separated
> from the individual handlers and from the event objects.
> Incidentally, if you look at my last rendition, there is no MPL involved.

It all depends on your design - as to how you implement the observer
pattern - spraying global variables all over the place or using proper
encapsulation. I am not much into Boost Signals but if it results in
clean separation then one should go for it. I just suggested a way to
implement the whole thing using simple C++ & basic design patterns
without any external library.

>
> IMO, this is just another means of downcasting. It's safer than a raw
> static
> cast because the types will be checked automatically, but not any better
> than
> the map solution (Which encapsulates the type check and downcast).

Well, IMO, polymorphically invoking virtual functions is better than
downcasting.

> This of course is the traditional OO wisdom, but IMO, maps
> are a perfectly legitimate means of dispatching.

If it results in significant performance gains then, of course, yes.
But you cannot know that until you actually measure the performance.
Design wise, I'd prefer the OO approach.

Since I have just read the rest of the thread, I would like to add
that Boost ASIO and ACE both are designed for this kind of
communication stuff. I don't know about ASIO but I do know that ACE
does use RTTI, virtual functions and design patterns. I don't think it
makes any significant performance difference. As a matter of fact,
using templates would often result in faster code than using straight
function pointers. A better strategy for Robert would be to actually
measure it or use one of Boost ASIO or ACE libraries.

--
Best regards,
Asif

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net