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

34 lines
789 B
D
Raw Normal View History

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