This repository has been archived on 2022-11-09. You can view files and clone it, but cannot push or open issues or pull requests.
patterns-old/lesson_2/CurrentConditionsDisplay.hpp

39 lines
899 B
C++
Raw Normal View History

2021-11-01 08:54:58 +00:00
/*
* CurrentConditionsDisplay.hpp
*
* Created on: 31 окт. 2021 г.
* Author: alexander
*/
#pragma once
#include "Observer.hpp"
#include "DisplayElement.hpp"
#include "WeatherData.hpp"
class CurrentConditionsDisplay: public Observer, public DisplayElement
{
private:
float temperature;
float humidity;
WeatherData &weatherData;
public:
CurrentConditionsDisplay(WeatherData &weatherData) :
temperature(0.0), humidity(0.0), weatherData(weatherData)
{
weatherData.registerObserver(*this);
}
void update(float temperature, float humidity, float pressure) override
{
this->temperature = temperature;
this->humidity = humidity;
display();
}
void display() const override
{
std::cout << "Current conditions: " << temperature << "F degrees and " << humidity << "% humidity" << std::endl;
}
};