I have class A and list of A objects. A has a function f that should be executed every X seconds (for the first instance every 1 second, for the seconds instance every 5 seconds, etc.).
I have a scheduler class that is responsible to execute the functions at the correct time.
What i thought to do is to create a new class, ATime, that will hold ptr to A instance and the time A::f should be executed. The scheduler will hold a min priority queue of Atime.
- Do you think it is the correct implementation?
- Should ATime be a nested class of the scheduler?
From what you describe, sounds like it could work 🙂
IMHO class
ATimebelongs to the scheduler more than to A. It is necessary for the scheduler to do its job, and it is not needed for A. In fact, A (and the rest of the world) need not even know about its existence – so putting it a private nested class of the scheduler would be appropriate for me.