module observer.request.forecastdisplay; import observer.request.displayelement; import observer.request.observer; import observer.request.weatherdata; import std.stdio : write, writeln; import std.format : format; class ForecastDisplay : Observer, DisplayElement { private: float currentPressure = 29.92f; float lastPressure; WeatherData weatherData; public: this(WeatherData weatherData) { this.weatherData = weatherData; weatherData.registerObserver(this); } override void update() { lastPressure = currentPressure; currentPressure = weatherData.getPressure; display(); } override void display() { write("Forecast: "); if (currentPressure > lastPressure) { writeln("Improving weather on the way!"); } else if (currentPressure == lastPressure) { writeln("More of the same"); } else if (currentPressure < lastPressure) { writeln("Watch out for cooler, rainy weather"); } } }