Beispiel #1
0
        private static void ObserverScenario()
        {
            var joao    = new Observer("João");
            var eduardo = new Observer("Eduardo");
            var bill    = new Observer("Bill");

            var amazon    = new StockExchange("Amazon", NextDecimal());
            var microsoft = new StockExchange("Microsoft", NextDecimal());

            amazon.Subscribe(joao);
            amazon.Subscribe(eduardo);

            microsoft.Subscribe(eduardo);
            microsoft.Subscribe(bill);

            Console.WriteLine("");
            Console.WriteLine("------------------");
            Console.WriteLine("");

            for (int i = 0; i < 5; i++)
            {
                amazon.Value    = NextDecimal();
                microsoft.Value = NextDecimal();

                if (i == 1)
                {
                    amazon.UnSubscribe(eduardo);
                }
            }
        }