ChangePrice() 공개 메소드

public ChangePrice ( ) : void
리턴 void
예제 #1
0
        private static void Observer()
        {
            Product product = new Product();

            // 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");

            //Lets use ArrayList for first two shops
            product.Suscribe(shop1);
            product.Suscribe(shop2);

            //Lets use event-delegate for other two shops
            product.Suscribe2(shop3);
            product.Suscribe2(shop4);

            Console.WriteLine("Todas las tiendas se han suscrito");

            //Now lets try chaging the products price, this should update the shops automatically
            product.ChangePrice(23.0f); //<------------------Notifica a todas las tiendas

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

            Console.WriteLine("La tienda 2 y 4 han cancelado su suscripción");

            //Now lets try changing the products price again
            product.ChangePrice(26.0f);//<------------------Notifica a la tienda 1 y 3

            Console.Read();
        }
예제 #2
0
        static void Main()
        {
            Product product = new Product();

            product.AddObserver(new CustomerObserver());

            product.ChangePrice();

            Console.Read();
        }