Пример #1
0
        static void Main(string[] args)
        {
            // Instantiate
            var subject       = new Subject();
            var redObserver   = new Observer(ConsoleColor.Red);
            var blueObserver  = new Observer(ConsoleColor.Blue);
            var whiteObserver = new Observer(ConsoleColor.White);

            // Subscribing to quantity changes
            subject.OnQuantityUpdated += redObserver.ObserverQuantity;
            subject.OnQuantityUpdated += blueObserver.ObserverQuantity;
            subject.OnQuantityUpdated += whiteObserver.ObserverQuantity;

            // Update quantity on the Subject
            subject.UpdateQuantity(27);
            Console.WriteLine();
            subject.UpdateQuantity(7);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var subject        = new Subject();
            var greenObserver  = new Observer(ConsoleColor.Green);
            var redObserver    = new Observer(ConsoleColor.Red);
            var yellowObserver = new Observer(ConsoleColor.Yellow);

            subject.OnQuantityUpdated += greenObserver.ObserverQuantity;
            subject.OnQuantityUpdated += redObserver.ObserverQuantity;
            subject.OnQuantityUpdated += yellowObserver.ObserverQuantity;

            subject.UpdateQuantity(12);
            subject.UpdateQuantity(5);

            Console.WriteLine("Enter a key to quit.");
            Console.Read();
        }