Files
porterskyandQwen 3.8 27B 6e0e45110a 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>
2026-10-06 16:26:53 +02:00

54 lines
1.3 KiB
C++

// ======================================================
//
// Represents a Pelican crossing
//
// ======================================================
#ifndef PELICAN_H
#define PELICAN_H
#include "Subject.h"
class PelicanTimer;
class Pole;
class Pelican : public Subject {
public:
Pelican();
~Pelican();
// call when the WAIT button has been pressed
void press(void);
// states that a Pelican can be in
enum PelicanState { RED_STATE, YELLOW_FLASHING, GREEN_TIMING, GREEN_IDLE, YELLOW_STATE };
bool isPressed() const { return pressed; }
PelicanState getState() const { return state; }
private:
// state that this Pelican is in
PelicanState state;
// called by PeleicanTimer when the lights need to change
void timerExpired(void);
const unsigned int RED_TIME;
const unsigned int YELLOW_TIME;
const unsigned int GREEN_TIME;
const unsigned int FLASH_TIME;
// indicates whether the WAIT light should be on
bool pressed;
// Timer that indicates when the lights should change
PelicanTimer *myTimer;
private:
// prevent general use of copy ctor and operator=
Pelican(const Pelican &);
Pelican &operator=(const Pelican &);
};
#endif