public override void Show()
        {
            Console.WriteLine("***Observer Pattern Demo***");
            Console.WriteLine("Raising Noise alarm if noise level goes beyond 80dB.");
            var noiseAlarm = new NoiseAlarm();

            // Type 1: Registering for raising alaram is hidden in observer.
            _noiseObserver = new NoiseObserver(noiseAlarm);

            // Type 2: Registering event outside the observer.
            _noiseObserverTwo             = new NoiseObserverTwo();
            _noiseObserverTwo.RaiseAlarm += noiseAlarm.RaiseAlarm;

            SimulateNoiseLevelVariantion();
        }
Beispiel #2
0
 public NoiseObserver(NoiseAlarm alarm)
 {
     _noiseAlarm = alarm;
 }