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:
+27
-28
@@ -1,28 +1,27 @@
|
||||
// ======================================================
|
||||
//
|
||||
// This class specializes the Timer to enable it to
|
||||
// stimulate a Pelican
|
||||
//
|
||||
// ======================================================
|
||||
|
||||
#ifndef PELICANTIMER_H
|
||||
#define PELICANTIMER_H
|
||||
|
||||
#include "Pelican.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class PelicanTimer : public Timer {
|
||||
public:
|
||||
typedef void (Pelican::*TargetFunc)();
|
||||
|
||||
PelicanTimer(Pelican &target, TargetFunc targetFunc);
|
||||
|
||||
// TODO: Rename this function to doExpired. The parameters and return type are unchanged.
|
||||
virtual void tick();
|
||||
|
||||
private:
|
||||
Pelican &myTarget;
|
||||
TargetFunc myTargetFunc;
|
||||
};
|
||||
|
||||
#endif
|
||||
// ======================================================
|
||||
//
|
||||
// This class specializes the Timer to enable it to
|
||||
// stimulate a Pelican
|
||||
//
|
||||
// ======================================================
|
||||
|
||||
#ifndef PELICANTIMER_H
|
||||
#define PELICANTIMER_H
|
||||
|
||||
#include "Pelican.h"
|
||||
#include "Timer.h"
|
||||
|
||||
class PelicanTimer : public Timer {
|
||||
public:
|
||||
typedef void (Pelican::*TargetFunc)();
|
||||
|
||||
PelicanTimer(Pelican &target, TargetFunc targetFunc);
|
||||
|
||||
void doExpired();
|
||||
|
||||
private:
|
||||
Pelican &myTarget;
|
||||
TargetFunc myTargetFunc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user