public void NotifyObserver(Observable observable) { foreach (Observer ob in this.Observers) { ob.update(observable); } }
public void update(Observable observable) { Water water = (Water)observable; if (water.GetTemp() >= 40) { Console.WriteLine("当前水的状态:温水"); } else if(water.GetTemp() < 40) { Console.WriteLine("当前水的状态:凉白开"); } }
public void update(Observable observable) { Water water = (Water)observable; Console.WriteLine("当前水的温度是:" + water.GetTemp()); }