I am trying to understand how to implement push vs pull notifications using Java built-in Observer.
the Observable
class has 2 methods notifyObservers()
and notifyObservers(Object arg)
I want to understand the differnce between them.
so I tried this
@Override
public void update(Observable o, Object arg) {
/*
if (o instanceof WeatherData) {
WeatherData weatherData = (WeatherData) o;
this.temperature = weatherData.getTemperature();
this.humidity = weatherData.getHumidity();
}*/
if (arg instanceof WeatherData) {
WeatherData weatherData = (WeatherData) arg;
this.temperature = weatherData.getTemperature();
this.humidity = weatherData.getHumidity();
}
display();
}
and in my observable class
setChanged();
//notifyObservers();
notifyObservers(this);
both objects can be cast down to WeatherData(the Observer) and then get the data from them.
using both methods seem like push notification-type for me, so what is the difference? and how can I implement pull notification-type using it?
Aucun commentaire:
Enregistrer un commentaire