static void Main(string[] args)
        {
            var stockObservable = new Observable <Stock>();

            var microsoftObserver = new MicrosoftStockObserver();

            microsoftObserver.Subscribe(stockObservable);

            var googleObserver = new GoogleStockObserver();

            googleObserver.Subscribe(stockObservable);

            stockObservable.Subject = new Stock("Microsoft", 10);
            microsoftObserver.Unsubscribe();
            stockObservable.Subject = new Stock("Microsoft", 20);
            stockObservable.Subject = new Stock("Microsoft", 30);
            microsoftObserver.Subscribe(stockObservable);
            stockObservable.Subject = new Stock("Microsoft", 40);
            stockObservable.Subject = new Stock("Google", 60);
            googleObserver.Unsubscribe();
            stockObservable.Subject = new Stock("Google", 70);
            stockObservable.Subject = new Stock("Google", 80);
            googleObserver.Subscribe(stockObservable);
            stockObservable.Subject = new Stock("Google", 90);

            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var stockObservable = new Observable <Stock>();

            var microsoftObserver = new MicrosoftStockObserver();

            microsoftObserver.Subscribe(stockObservable);

            var googleObserver = new GoogleStockObserver();

            googleObserver.Subscribe(stockObservable);

            stockObservable.Subject = new Stock("Microsoft", 10);
            microsoftObserver.Unsubscribe();
            stockObservable.Subject = new Stock("Microsoft", 20);
            stockObservable.Subject = new Stock("Microsoft", 30);
            microsoftObserver.Subscribe(stockObservable);
            stockObservable.Subject = new Stock("Microsoft", 40);
            stockObservable.Subject = new Stock("Google", 60);
            googleObserver.Unsubscribe();
            stockObservable.Subject = new Stock("Google", 70);
            stockObservable.Subject = new Stock("Google", 80);
            googleObserver.Subscribe(stockObservable);
            stockObservable.Subject = new Stock("Google", 90);
            stockObservable.Error(new StockNotFoundException("Some error occured!"));
            stockObservable.Completed();
            Console.ReadLine();
        }