feat(cmat): implement Ex41 observer pattern
Refactor the Pelican crossing exercise to use the Observer pattern: Pelican acts as Subject and each Pole observes it, replacing direct calls through the owned Pole pointer. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
|
||||
|
||||
#include "Subject.h"
|
||||
#include "Observer.h"
|
||||
|
||||
// TODO: Implement the Subject::attach() member function that adds an Observer to the set
|
||||
void Subject::attach(Observer* observer) {
|
||||
m_observers.insert(observer);
|
||||
}
|
||||
|
||||
// TODO: Implement the Subject::notify() member function that calls all the update functions
|
||||
void Subject::notify() {
|
||||
for (auto* observer : m_observers) {
|
||||
observer->update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user