static void Main() { ProductNotifier productNotifier = new ProductNotifier(); ProductObserver productObserver = new ProductObserver("*****@*****.**"); productNotifier.Subscribe(productObserver); productNotifier.Subscribe(new ProductObserver("*****@*****.**")); productNotifier.Subscribe(new ProductObserver("*****@*****.**")); Console.ReadKey(); Console.WriteLine("\n\n"); productNotifier.ProductCount++; //increase product count - then all the subscribed members will get notification Console.ReadKey(); Console.WriteLine("\n\n"); productNotifier.Unsubscribe(productObserver); Console.ReadKey(); Console.WriteLine("\n\n"); productNotifier.ProductCount++; //increase product count - then all the subscribed members will get notification Console.ReadKey(); }
public void Unsubscribe(ProductObserver observer) { Console.WriteLine(observer.ObserverName + " Unsubscribed from notification"); productObserver.Remove(observer); }
public void Subscribe(ProductObserver observer) { Console.WriteLine(observer.ObserverName + " Subscribed for notification"); productObserver.Add(observer); }