Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-05-09 08:27:16


From: "Jesse Jones" <jesjones_at_[hidden]>

> At 3:15 PM +0300 5/8/01, Peter Dimov wrote:

> >class Timer
> >{
> >public:
> > Timer(function<void> const & onTick, int interval);
> >};
>
> I like this better than the cookie approach, but it's still not
> quite as clean as my original approach. And, as I mentioned, timers

I'd argue that this is a cleaner approach. An active timer is a resource,
and a resource should be represented by an object.

You can still overlay a (local) 'Timer manager' (std::vector<Timer>?) on top
of that, but the design is more flexible, because you can have more than one
Timer container and additional 'free' Timers active, if necessary.

> are the easy case. The harder case is handling menu commands. I don't
> want 46 cookies floating around and I don't want 46 helper objects
> either. :-)

46 cookies are a pain because of the resource management issues, but 46
helper objects do not present the same problem. They manage themselves. You
only have to control their lifetime - which you do in the original design
anyway by using explicit 'Add' and 'Remove' functions. Constructors and
destructors do a better job.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk