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/request/currentconditionsdisplay.d

34 lines
821 B
D

module observer.request.currentconditionsdisplay;
import observer.request.displayelement;
import observer.request.observer;
import observer.request.weatherdata;
import std.stdio : writeln;
import std.format : format;
class CurrentConditionsDisplay : Observer, DisplayElement
{
private:
float temperature;
float humidity;
WeatherData weatherData;
public:
this(WeatherData weatherData)
{
this.weatherData = weatherData;
weatherData.registerObserver(this);
}
override void update()
{
this.temperature = weatherData.getTemperature;
this.humidity = weatherData.getHumidity;
display();
}
override void display()
{
writeln("Current conditions: %3.1f".format(temperature), "F degrees and %3.1f%% humidity".format(humidity));
}
}