Re: Lahman, how ya doing?
- From: glhansen@xxxxxxxxxxxxxxxxxxxxx (Gregory L. Hansen)
- Date: Mon, 25 Apr 2005 21:09:13 +0000 (UTC)
In article <epeq61tbch76mo7dlkgqlj36vqrt9rfov2@xxxxxxx>,
Robert C. Martin <u.n.c.l.e.b.o.b@xxxxxxxxxxxxxxxx> wrote:
>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.
Just when I think I have the basic infrastructure ready to go, with the
rest of the problem reduced to one particular block or another, I get a
sensible suggestion.
I've already realized a weakness in that last loop, and changed it so that
it can be replaced with
clock.run(10); // run for 10 seconds
That loop is the kind of grunt work that shouldn't appear in the
interface. And the length of a tick may be an input parameter,
determining the time resolution, but ticks shouldn't be part of normal
interfacing.
--
"When the fool walks through the street, in his lack of understanding he
calls everything foolish." -- Ecclesiastes 10:3, New American Bible
.
- References:
- Lahman, how ya doing?
- From: Gregory L. Hansen
- Re: Lahman, how ya doing?
- From: Robert C . Martin
- Lahman, how ya doing?
- Prev by Date: Re: Lahman, how ya doing?
- Next by Date: Re: Objective criticism of inheritance
- Previous by thread: Re: Lahman, how ya doing?
- Next by thread: Re: Lahman, how ya doing?
- Index(es):
Relevant Pages
|