refactor(Ex22): apply template method to Timer
Rename the virtual tick() override in PelicanTimer to doExpired() and give the base Timer class a non-virtual tick() that checks for expiration and dispatches to doExpired(). The exercise starting point now matches SolutionEx22. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
This commit is contained in:
+30
-27
@@ -1,27 +1,30 @@
|
||||
// ======================================================
|
||||
//
|
||||
// A general-purpose countdown timer
|
||||
// To use this class, specialize it
|
||||
// and override tick()
|
||||
//
|
||||
// ======================================================
|
||||
|
||||
#ifndef timer_H
|
||||
#define timer_H
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
|
||||
void timeoutRequest(int seconds);
|
||||
|
||||
virtual void tick() = 0;
|
||||
|
||||
protected:
|
||||
bool isExpired();
|
||||
|
||||
private:
|
||||
int timeToGo;
|
||||
};
|
||||
|
||||
#endif
|
||||
// ======================================================
|
||||
//
|
||||
// A general-purpose countdown timer
|
||||
// To use this class, specialize it
|
||||
// and override tick()
|
||||
//
|
||||
// ======================================================
|
||||
|
||||
#ifndef timer_H
|
||||
#define timer_H
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
|
||||
void timeoutRequest(int seconds);
|
||||
|
||||
void tick();
|
||||
|
||||
private:
|
||||
virtual void doExpired() = 0;
|
||||
|
||||
protected:
|
||||
bool isExpired();
|
||||
|
||||
private:
|
||||
int timeToGo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user