Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HeadFirstDesignPatterns.Ch02TheObserverPattern.WeatherStation
- {
- class ForecastDisplay : Observer, DisplayElement
- {
- private float currentPressure = 29.92F;
- private float lastPressure;
- private WeatherData weatherData;
- public ForecastDisplay(WeatherData weatherData)
- {
- this.weatherData = weatherData;
- weatherData.RegisterObserver(this);
- }
- public void update(float temperature, float humidity, float pressure)
- {
- lastPressure = currentPressure;
- currentPressure = pressure;
- display();
- }
- public void display()
- {
- Console.WriteLine("Forecast: ");
- if (currentPressure > lastPressure)
- {
- Console.WriteLine("Improving weather on the way!");
- }
- else if (currentPressure == lastPressure)
- {
- Console.WriteLine("More of the same");
- }
- else if (currentPressure < lastPressure)
- {
- Console.WriteLine("Watch out for cooler, rainy weather");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement