public void update(Observable obs, Object arg)
{
if (obs instanceof WeatherData) {
WeatherData weatherData = (WeatherData)obs;
this.temperature = weatherData.getTemperature();
this.humidity = weatherData.getHumidity();
display();
}
}
The above piece of code is from Head First Design Patterns. An event is going to fire for every change that occurs, and this will be sent to all the observers whether the event is what they expect or not. The if
block helps in letting the code decide which events to handle.
So create observable for every such scenario will be a good practice right?