Esempio n. 1
0
        static void Main(string[] args)
        {
            DummyProduct product = new DummyProduct();

            // We have four shops wanting to keep updated price set by product owner
            Shop shop1 = new Shop("Shop 1");
            Shop shop2 = new Shop("Shop 2");

            Shop shop3 = new Shop("Shop 3");
            Shop shop4 = new Shop("Shop 4");

            //Attach the shops to the subscriber
            product.Attach(shop1);
            product.Attach(shop2);

            product.Attach(shop3);
            product.Attach(shop4);

            //changing the products price and the amount, this should update the shops automatically
            product.ChangePriceAndAmount(23.0f, 10);

            //shop2 and shop 4 are not interested in new prices so they unsubscribe
            product.Detach(shop2);
            product.Detach(shop4);

            //Now lets try changing the products price and amount again
            product.ChangePriceAndAmount(26.0f, 20);

            Console.Read();
        }
Esempio n. 2
0
 public void Detach(Shop product)
 {
     //detach the observers with subjects
     list.Remove(product);
 }
Esempio n. 3
0
 public void Attach(Shop product)
 {
     //attach the observers with subjects
     list.Add(product);
 }