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:
2026-10-05 14:35:16 +02:00
co-authored by Qwen 3.8 27B
parent 73114f1bab
commit db0d7b9bee
4 changed files with 89 additions and 83 deletions
+9 -11
View File
@@ -1,11 +1,9 @@
#include "PelicanTimer.h"
PelicanTimer::PelicanTimer(Pelican &target, TargetFunc targetFunc) : myTarget(target), myTargetFunc(targetFunc) {}
void PelicanTimer::tick() {
if (isExpired()) {
(myTarget.*myTargetFunc)();
}
}
#include "PelicanTimer.h"
PelicanTimer::PelicanTimer(Pelican &target, TargetFunc targetFunc) : myTarget(target), myTargetFunc(targetFunc) {}
void PelicanTimer::doExpired() {
(myTarget.*myTargetFunc)();
}