Exemple #1
0
        static void Main(string[] args)
        {
            IBMStock iBMStock = new IBMStock("IBM", 100);

            iBMStock.Attach(new Investor("Ram"));
            iBMStock.Attach(new Investor("Shyam"));
            iBMStock.Price = 200;
            iBMStock.Price = 300.20;
        }
        private static void BasicObserverPattern()
        {
            Stock _IBMStock = new IBMStock("IBM", 100);

            IInvestor _Investor1 = new Investor("Investor1");

            _IBMStock.Subscribe(_Investor1);

            IInvestor _Investor2 = new Investor("Investor2");

            _IBMStock.Subscribe(_Investor2);
        }
        static void Main(string[] args)
        {
            // Create subject
            Stock stock = new IBMStock("IBM", 21.76);

            // Create observers
            IInvestor investor  = new Investor("Investor 1");
            IInvestor investor2 = new Investor("Investor 2");

            // Attach observers to subject
            stock.Attach(investor);
            stock.Attach(investor2);

            // Update prices (will notify investors)
            stock.Price = 21.80;
            stock.Price = 21.86;
            stock.Price = 21.90;
            stock.Price = 21.99;
        }