public static void Behavioral_ObserverDemo2() { var statusBar = new StatusBar(); var stockListView = new StockListView(); var stock1 = new Stock("stock1", 10); var stock2 = new Stock("stock2", 20); var stock3 = new Stock("stock3", 30); // The status bar shows the popular stocks statusBar.AddStock(stock1); statusBar.AddStock(stock2); // The stock view list shows all stocks stockListView.AddStock(stock1); stockListView.AddStock(stock2); stockListView.AddStock(stock3); // Causes both statusBar and stockListView to get refreshed stock2.SetPrice(21); // Causes only the stockListView to get refreshed. (statusBar // is not watching this stock.) stock3.SetPrice(9); }
public ObserverPatternMain() { // Stocks Stock stock1 = new Stock("EMR", 1); Stock stock2 = new Stock("SHS", 3); Stock stock3 = new Stock("JSK", 7); // Presentation Layers var statusBar = new StatusBar(); var stockListView = new StockListView(); statusBar.AddStock(stock1); stockListView.AddStock(stock1); stockListView.AddStock(stock2); stockListView.AddStock(stock3); // stock1.Price = 10; stock2.Price = 12; }
void LoadOrdersList() { List <Stock> stock = new List <Stock>(); stock = Stocks_controller.Get_Stocks(); StockListView.Clear(); StockListView.GridLines = true; StockListView.View = View.Details; StockListView.Columns.Add("Order ID", 100, HorizontalAlignment.Left); StockListView.Columns.Add("Item Name", 150, HorizontalAlignment.Left); StockListView.Columns.Add("Quantity", 100, HorizontalAlignment.Left); foreach (Stock STk in stock) { ListViewItem Ord = new ListViewItem(STk.Id.ToString()); Ord.SubItems.Add(STk.Name); Ord.SubItems.Add(STk.Quantity); StockListView.Items.Add(Ord); } }
static void Main(string[] args) { Stock stock1 = new Stock("TCS", 4512); Stock stock2 = new Stock("Reliance", 1200); Stock stock3 = new Stock("HUL", 4568); StatusBar objStatusBar = new StatusBar(); StockListView objStockLstView = new StockListView(); objStatusBar.addStocks(stock1); objStatusBar.addStocks(stock2); objStockLstView.addStocks(stock1); //objStockLstView.addStocks(stock2); //objStockLstView.addStocks(stock3); stock1.setStockPrice(5000); stock2.setStockPrice(10000); stock3.setStockPrice(20033); Console.ReadLine(); }
static void Main(string[] args) { // Pull Style Observer Pattern var pullStyleDataSource = new Solution.PullStyle.DataSource(); var pullStyleChart = new Solution.PullStyle.Chart(pullStyleDataSource); pullStyleDataSource.Attach(pullStyleChart); var pullStyleSpreadSheet = new Solution.PullStyle.SpreadSheet(pullStyleDataSource); pullStyleDataSource.Attach(pullStyleSpreadSheet); pullStyleDataSource.SetValue(10); pullStyleDataSource.Dettach(pullStyleSpreadSheet); pullStyleDataSource.SetValue(50); // Push Style Observer Pattern var pushStyleDataSource = new Solution.PushStyle.DataSource(); var pushStyleChart = new Solution.PushStyle.Chart(); pushStyleDataSource.Attach(pushStyleChart); var pushStyleSpreadSheet = new Solution.PushStyle.SpreadSheet(); pushStyleDataSource.Attach(pushStyleSpreadSheet); pushStyleDataSource.SetValue(10); pushStyleDataSource.Dettach(pushStyleSpreadSheet); pushStyleDataSource.SetValue(50); Console.WriteLine("--- Exercise ---"); var listOfStocks = new List <Stock> { new Stock("Stock1", 10), new Stock("Stock2", 20), new Stock("Stock3", 30), }; var statusBar = new StatusBar(); statusBar.AddStock(listOfStocks[0]); statusBar.AddStock(listOfStocks[1]); var stockListView = new StockListView(); stockListView.AddStock(listOfStocks[0]); stockListView.AddStock(listOfStocks[1]); stockListView.AddStock(listOfStocks[2]); listOfStocks[0].SetPrice(15); listOfStocks[1].SetPrice(25); listOfStocks[2].SetPrice(35); listOfStocks[1].Dettach(statusBar); listOfStocks[0].SetPrice(25); listOfStocks[1].SetPrice(35); listOfStocks[2].SetPrice(45); Console.ReadLine(); }
public UIElement GetListView() { StockListView view = new StockListView(listViewModel); return(view); }