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.WeatherStationWithEventsAndDelegates
- {
- class ForecastDisplayWithEventsAndDelegates : IObserverWithEventsAndDelegates, DisplayElementWithEventsAndDelegates
- {
- private float currentPressure = 29.92F;
- private float lastPressure;
- public void Update(float temperature, float humidity, float pressure)
- {
- lastPressure = currentPressure;
- currentPressure = pressure;
- Display();
- }
- public void Display()
- {
- System.Console.WriteLine("Forecast: ");
- if (currentPressure > lastPressure)
- {
- System.Console.WriteLine("Improving weather on the way!");
- }
- else if (currentPressure == lastPressure)
- {
- System.Console.WriteLine("More of the same");
- }
- else if (currentPressure < lastPressure)
- {
- System.Console.WriteLine("Watch out for cooler, rainy weather");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement