static void Main(string[] args) { Observable obe = new ConcreteObservable(); ConcreteObserver concreteObserver_1 = new ConcreteObserver("ConcreteObserver_1"); ConcreteObserver concreteObserver_2 = new ConcreteObserver("ConcreteObserver_2"); ConcreteObserver concreteObserver_3 = new ConcreteObserver("ConcreteObserver_3"); obe.AddObserver(concreteObserver_1); obe.AddObserver(concreteObserver_3); obe.NotifyObservers(); obe.NotifyObservers(); obe.RemoveObserver(concreteObserver_3); obe.AddObserver(concreteObserver_2); obe.NotifyObservers(); obe.AddObserver(concreteObserver_3); obe.NotifyObservers(); PrintObserverInfo(concreteObserver_1); PrintObserverInfo(concreteObserver_2); PrintObserverInfo(concreteObserver_3); }
static void Main(string[] args) { ConcreteObservable concreteObservable = new ConcreteObservable(); concreteObservable.Register(new ConcreteObserverA("First")); concreteObservable.Register(new ConcreteObserverB("Second")); var observerToRegister = new ConcreteObserverB("Third"); concreteObservable.Register(observerToRegister); concreteObservable.NotifyObserver(24); concreteObservable.Unregister(observerToRegister); Console.WriteLine("=================================="); concreteObservable.NotifyObserver(42); Console.ReadKey(); }