コード例 #1
0
        /// <summary>
        /// Runners the observer.
        /// </summary>
        public static void RunnerObserver()
        {
            Product laptop = new Product("DELL", 1000);

            Console.WriteLine("--------Customer 1 and Customer 2 is subscribed to the Laptop Product----------");
            //// attach or subscribe customer 1
            Customer customer1 = new Customer("customer 1");

            laptop.Subscribe(customer1);
            //// attach or subscribe customer 2
            Customer customer2 = new Customer("customer 2");

            laptop.Subscribe(customer2);

            //// publish notification to the subscribers
            laptop.Price = 800;

            Console.WriteLine("--------customer 2 is unsubscribed and customer 3 is subscribed to the Laptop Product----------");
            //// customer 2 is unsubscribed and customer 3 is subscribed
            laptop.UnSubscribe(customer2);
            Customer customer3 = new Customer("customer 3");

            laptop.Subscribe(customer3);
            laptop.Price = 900;
        }
コード例 #2
0
        /// <summary>
        /// the method for observer
        /// </summary>
        public void Observer()
        {
            Product laptop = new Product("DELL", 30000);

            Console.WriteLine("Customer 1 and Customer 2 is subscribed to the Laptop Product");
            //// attach or subscribe customer 1
            Customer customer1 = new Customer("customer 1");

            laptop.Subscribe(customer1);
            //// attach or subscribe customer 2
            Customer customer2 = new Customer("customer 2");

            laptop.Subscribe(customer2);
            laptop.Price = 25000;
        }