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:
+6
-3
@@ -3,22 +3,25 @@
|
||||
#define POLE_H
|
||||
|
||||
#include "Light.h"
|
||||
#include "Observer.h"
|
||||
#include "Pelican.h"
|
||||
|
||||
class Pole {
|
||||
class Pole : public Observer {
|
||||
public:
|
||||
Pole(int x, int y);
|
||||
Pole(int x, int y, Pelican&);
|
||||
~Pole();
|
||||
|
||||
void setTrafficLights(Pelican::PelicanState state);
|
||||
void setWaitLight(bool pressed);
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
enum LightName { RED_LIGHT, YELLOW_LIGHT, GREEN_LIGHT, GREEN_MAN, RED_MAN };
|
||||
|
||||
Light *lights[RED_MAN + 1];
|
||||
|
||||
Light *waitLight;
|
||||
Pelican& pelican;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user