Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
 public void Unsubscribe(ProductObserver observer)
 {
     Console.WriteLine(observer.ObserverName + " Unsubscribed from notification");
     productObserver.Remove(observer);
 }
Exemplo n.º 3
0
 public void Subscribe(ProductObserver observer)
 {
     Console.WriteLine(observer.ObserverName + " Subscribed for notification");
     productObserver.Add(observer);
 }