module observer.weatherdata; import observer.subject; import observer.observer; import std.algorithm : remove, countUntil; class WeatherData : Subject { private: Observer[] observers; float temperature, humidity, pressure; public: override void registerObserver(Observer o) { observers ~= o; } override void removeObserver(Observer o) { observers.remove(observers.countUntil(o)); } override void notifyObservers() { foreach (Observer o; observers) { o.update(temperature, humidity, pressure); } } void measurementsChanged() { notifyObservers(); } void setMeasurements(float temperature, float humidity, float pressure) { this.temperature = temperature; this.humidity = humidity; this.pressure = pressure; measurementsChanged(); } @property float getTemperature() { return temperature; } @property float getHumidity() { return humidity; } @property float getPressure() { return pressure; } }