Advertisement
Fhernd

CurrentConditionsDisplay.cs

Mar 12th, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HeadFirstDesignPatterns.Ch02TheObserverPattern.WeatherStation
  8. {
  9.     class CurrentConditionsDisplay : Observer, DisplayElement
  10.     {
  11.         private float temperature;
  12.         private float humidity;
  13.         private Subject weatherData;
  14.  
  15.         public CurrentConditionsDisplay(Subject weatherData)
  16.         {
  17.             this.weatherData = weatherData;
  18.             weatherData.RegisterObserver(this);
  19.         }
  20.  
  21.         public void update(float temperature, float humidity, float pressure)
  22.         {
  23.             this.temperature = temperature;
  24.             this.humidity = humidity;
  25.             display();
  26.         }
  27.  
  28.         public void display()
  29.         {
  30.             Console.WriteLine(String.Format("Current conditions: {0}F degrees and {1}% humidity", temperature,humidity));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement