Beispiel #1
0
        static void Main(string[] args)
        {
            WeatherStation station      = new WeatherStation();
            MobileDevice   mobileDevice = new MobileDevice(station);

            station.Add(mobileDevice);
            station.Notify();
        }
        /// <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();
        }
        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();
        }