예제 #1
0
        public void removeObserver(LocalStocks l)
        {
            var i = observers.IndexOf(l);

            if (i >= 0)
            {
                observers.RemoveAt(i);
            }
        }
        static void Main(string[] args)
        {
            // Observers
            Selections selections   = new Selections();
            ChangeTen  changeTen    = new ChangeTen();
            Average    averagePrice = new Average();

            LocalStocks ls = new LocalStocks();

            // Register Observers
            ls.RegisterObserver(selections);
            ls.RegisterObserver(changeTen);
            ls.RegisterObserver(averagePrice);

            // Read in Report
            ls.ReadIn("Ticker.dat");

            Console.ReadKey();
        }
예제 #3
0
        static void SimulateObservers(List<StockData> stockdata)
        {
            LocalStocks stocks = new LocalStocks();
            AverageObserver average = new AverageObserver();
            Change10Observer change10 = new Change10Observer();
            SelectionObserver select = new SelectionObserver();

            stocks.Subscribe(average);
            stocks.Subscribe(change10);
            stocks.Subscribe(select);

            //stocks.ChangeHappens(stockdata.ElementAt(0));
            stocks.Notify();

            //stocks.ChangeHappens(stockdata.ElementAt(1));
            stocks.Notify();

            stocks.Unsubscribe(average);
            //stocks.ChangeHappens(stockdata.ElementAt(2));
            stocks.Notify();

            stocks.Unsubscribe(change10);
            stocks.Unsubscribe(select);
        }
예제 #4
0
 public void registerObserver(LocalStocks l)
 {
     observers.Add(l);
 }