This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/observer/delivery/forecastdisplay.d

39 lines
968 B
D

module observer.delivery.forecastdisplay;
import observer.delivery.displayelement;
import observer.delivery.observer;
import observer.delivery.weatherdata;
import std.stdio : write, writeln;
import std.format : format;
class ForecastDisplay : Observer, DisplayElement
{
private:
float currentPressure = 29.92f;
float lastPressure;
public:
this(WeatherData weatherData)
{
weatherData.registerObserver(this);
}
override void update(float temperature, float humidity, float pressure)
{
lastPressure = currentPressure;
currentPressure = pressure;
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");
}
}
}