private void NotifyAllSubscribers(Platinum platinum) { foreach (var subs in this.subscribers) { subs.Notify(platinum); } }
public static void LaunchThird() { Gold gold = new Gold(3500); Platinum platinum = new Platinum(3700); PriceObserver priceObserver = new PriceObserver(); TimeObserver ts = new TimeObserver(); gold.addSubsriber(priceObserver); platinum.addSubsriber(priceObserver); gold.addSubsriber(ts); platinum.addSubsriber(ts); gold.PriceUp(); gold.PriceUp(); gold.PriceUp(); platinum.PriceUp(); randomLogicForStockMarket(gold, platinum); gold.RemoveObserver(ts); gold.RemoveObserver(priceObserver); gold.PriceUp(); gold.PriceUp(); gold.PriceUp(); }
private static void randomLogicForStockMarket(Gold gold, Platinum pl) { for (int i = 0; i < 10; i++) { var random = new Random(); var number = random.Next(0, 2); if (number == 0) { gold.PriceUp(); pl.PriceUp(); } else { gold.PriceDown(); pl.PriceDown(); } } }