Re: Lahman, how ya doing?
- From: Robert C. Martin <unclebob@xxxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 13:49:47 -0500
On Sun, 24 Apr 2005 19:48:53 +0000 (UTC),
glhansen@xxxxxxxxxxxxxxxxxxxxx (Gregory L. Hansen) wrote:
>#include "control.h"
>int main()
>{
> ControlBlock c1(1), c2(2), c3(3);
>
> Timer t1(3); // trigger every 3 seconds
> t1.add_task(&c1);
> t1.add_task(&c2);
>
> DoubleTimer t2(5,7); // event1 every 5 s, event2 every 7
> t2.add_task(&c3);
>
> Clock clock; // default 1 tick per second
> clock.add_timer(&t1);
> clock.add_timer(&t2);
>
> for (int i = 0; i < 10; i++)
> clock.tick();
>
> return 0;
>}
I would do this a bit differently. I'd build the Timer class so that
you could do this:
Timer timer;
timer.addTask(c1, 3); // do C1 every three seconds.
timer.addTask(c2, 3); // do C2 every three seconds.
timer.addTask(c3, 5); // do C3 every five seconds.
timer.addTask(c4, 7); // do C7 every seven seconds.
-----
Robert C. Martin (Uncle Bob) | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716
"The aim of science is not to open the door to infinite wisdom,
but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
.
- Follow-Ups:
- Re: Lahman, how ya doing?
- From: Gregory L. Hansen
- Re: Lahman, how ya doing?
- References:
- Lahman, how ya doing?
- From: Gregory L. Hansen
- Lahman, how ya doing?
- Prev by Date: Re: author of this article?
- Next by Date: Re: Lahman, how ya doing?
- Previous by thread: Lahman, how ya doing?
- Next by thread: Re: Lahman, how ya doing?
- Index(es):
Relevant Pages
|