static void Main(string[] args) { Console.WriteLine("=================Weather Staion================"); WeatherData weatherData = new WeatherData(); WeatherStation weatherStation = new WeatherStation(weatherData); AndriodPhoneDisplay andriodPhoneDisplay = new AndriodPhoneDisplay(weatherStation.weatherData); IPhonePhoneDisplay iPhonePhoneDisplay = new IPhonePhoneDisplay(weatherStation.weatherData); LCDDisplay lcdDisplay = new LCDDisplay(weatherStation.weatherData); weatherStation.Add(andriodPhoneDisplay); weatherStation.Add(iPhonePhoneDisplay); weatherStation.Add(lcdDisplay); Console.WriteLine("=================Weather check at #1 ================"); weatherStation.UpdateTemparature(30); Console.WriteLine("=================Weather check at #2 ================"); weatherStation.UpdateTemparature(60); Console.WriteLine("=================Weather check at #3 ================"); weatherStation.UpdateTemparature(25); Console.WriteLine("================================================"); Console.ReadLine(); }
static void Main(string[] args) { WeatherStation ipma = new WeatherStation(); Phone samsung = new Phone(ipma); Television lg = new Television(ipma); ipma.Add(samsung); ipma.Add(lg); ipma.NewTemperature(24.5); ipma.NewTemperature(25); }
static void Main(string[] args) { // Create weather station - Observable WeatherStation weatherStation = new WeatherStation(); // Create Displays - Observers TemperatureDisplay temperatureDisplay = new TemperatureDisplay(); WindDisplay windDisplay = new WindDisplay(); // Add Observers to Observable weatherStation.Add(temperatureDisplay); weatherStation.Add(windDisplay); // To demonstrate, manually triiger the Notify() of the observable weatherStation.Notify(); }
static void Main(string[] args) { WeatherStation station = new WeatherStation(); MobileDevice mobileDevice = new MobileDevice(station); station.Add(mobileDevice); station.Notify(); }
static void Main(string[] args) { WeatherStation station = new WeatherStation(37); PhoneDisplay display1 = new PhoneDisplay(station); PhoneDisplay display2 = new PhoneDisplay(station); PhoneDisplay display3 = new PhoneDisplay(station); station.Add(display1); station.Add(display2); station.Add(display3); display1.Display(); display2.Display(); display3.Display(); station.Temperature = 40; display1.Display(); display2.Display(); display3.Display(); }
/// <summary> /// Definition: /// The observer pattern defines a one to many dependencies between objects so that when one object changes state, /// all of it's dependencies are notified and updated automatically. /// </summary> static void Main(string[] args) { WeatherStation station = new WeatherStation(); TabletDisplay tabletDisplay = new TabletDisplay(station); PhoneDisplay phoneDisplay = new PhoneDisplay(station); station.Add(tabletDisplay); station.Add(phoneDisplay); station.Notify(); station.Remove(tabletDisplay); station.Notify(); station.Add(tabletDisplay); station.Notify(); Console.WriteLine("\n--- Let's update the temperatur --- "); station.UpdateTemperatur(50); Console.ReadKey(); }