I have the following notification sent for an Observer and Observable design pattern
private void changeEnvironment()
{
Random random = new Random();
season = SEASON[random.nextInt(3)];
dayInTime = DAY_IN_TIME[random.nextInt(2)];
temperature = random.nextInt(120);
setChanged();
notifyObservers(season);
notifyObservers(dayInTime);
notifyObservers(temperature);
}
However, in my:
public void update(Observable o, Object arg) {
}
How do I check whether it’s season, dayInTime, or temperature?
You can use the observer pattern in pull mode , which means that observable will pass itself to the observer ‘s
update().So , observer can get properties they want from the observable ‘s getters.I assume
temperature,dayInTime,seasonin your subject are bothintSo , you
Observable(i.e Subject) will looks like :Then your observer can get temperature, dayInTime , season by using the corresponding getters of your Observable :