static void Main(string[] args) { IDisplay display = new PortfolioDisplay(); List <Stock> stockList = new List <Stock>(); stockList.Add(new Stock("Google", 52.5)); stockList.Add(new Stock("Apple", 30.5)); stockList.Add(new Stock("Vestas", 10.5)); stockList.Add(new Stock("Microsoft", 33)); stockList.Add(new Stock("C25", 80)); stockList.Add(new Stock("Benchmark", 335)); IObserver observer1 = new Portfolio("PORTFOLIO_1", display); IObserver observer2 = new Portfolio("PORTFOLIO_2", display); IObserver observer3 = new Portfolio("PORTFOLIO_3", display); //Subscribes Observers to Subjects (Portfolios to stocks) stockList[0].Attach(observer1); stockList[1].Attach(observer2); stockList[1].Attach(observer1); stockList[2].Attach(observer3); stockList[3].Attach(observer2); stockList[4].Attach(observer1); stockList[5].Attach(observer2); Thread newThread = new Thread(() => updateValue(stockList)); //Makes thread run in updateValue method newThread.Start(); //Input for changing stock value, eg: "Vestas 5" do { string changeValue = Console.ReadLine(); string[] words = changeValue.Split(' '); foreach (var stock in stockList) { if (words[0] == stock.Name) { stock.Value = double.Parse(words[1]); } } } while (true); }
public Portfolio(string name, IDisplay display) { _name = name; _display = (PortfolioDisplay)display; }