コード例 #1
0
        static void Main(string[] args)
        {
            // initial stock price
            var initialStockPrice = new StockModel
            {
                StockName         = "Virtusa Stock Price",
                CurrentStockPrice = 1000,
                LastUpdated       = DateTime.Now
            };

            // subject to be observed
            var subject = new StockPrice(initialStockPrice);

            // attach observers
            AbstractObserver londonObserver  = new LondonStockPriceView(subject);
            AbstractObserver newYorkObserver = new NewYorkStockPriceView(subject);

            // change stock price
            subject.SetState(900);      Console.WriteLine();
            subject.SetState(1100);     Console.WriteLine();
            subject.SetState(1200);     Console.WriteLine();

            Console.ReadKey();
        }
コード例 #2
0
 public StockPrice(StockModel initalStockState)
 {
     CurrentStockState = initalStockState;
     Observers         = new List <AbstractObserver>();
 }
コード例 #3
0
 public override void Update(StockModel updatedModel)
 {
     this.MyStockDisplay = updatedModel;
     Display();
 }
コード例 #4
0
 public abstract void Update(StockModel updatedModel);