public void ShouldNotifyWhenObservableChange() { var station = new WeatherStation(); var display = new PhoneDisplay(station); station.SetTemperature(10); Assert.AreEqual(station.Temperature, display.Temperature); }
public PhoneCreatedEvent(string name, string manufacturer, PhoneDimensions dimensions, double weight, PhoneDisplay display, string cpuModel, int ram, string os, double price, List <PhoneMedia> media) { Name = name; Manufacturer = manufacturer; Dimensions = dimensions; Weight = weight; Display = display; CPUModel = cpuModel; RAM = ram; OS = os; Price = price; Media = media; }
static void Main(string[] args) { WeatherConditionStation weatherStation = new WeatherConditionStation(); while (true) { PhoneDisplay phoneDisplay = new PhoneDisplay(weatherStation); weatherStation.Add(phoneDisplay); weatherStation.Notify(); Thread.Sleep(5000); } }
private static void Observer_Pattern() { // TODO The Observer pattern defines one to many dependencies between objects so that when one object changes its state // TODO all of its dependencies are notified and updated automatically var weatherStation = new WeatherStation(); IObserver phoneDisplay = new PhoneDisplay(weatherStation); IObserver tabletDisplay = new TabletDisplay(weatherStation); // push the observer in the list weatherStation.Add(phoneDisplay); weatherStation.Add(tabletDisplay); Console.WriteLine("Observable Weather Station received new Temperature so it will update the observers"); //poll the date from observable for each observer in the list weatherStation.Notify(); }
public static void Main() { // create object that implements IObservable WeatherStation weatherStation = new WeatherStation(); // create object that implements IObserver and add IObservable object PhoneDisplay o1 = new PhoneDisplay(weatherStation); weatherStation.add(o1); Webpage o2 = new Webpage(weatherStation); weatherStation.add(o2); weatherStation.setTemprature(21); weatherStation.setTemprature(23); weatherStation.remove(o1); weatherStation.setTemprature(18); }