Instead of using built in class Observable and Observer I am trying to build it myself.
From docs I figured:
public class Observable{
private Set<Observer> observingMe=null;
private boolean amIchanged;
public void notifyObservers(Object args){
for(Observer o:observingMe){
o.update(args);
}
}
public void addObserver(Observer e){
observingMe.add(e);
}
}
public class Price implements Observable{
private int price;
public void setPrice(int newPrice){
price=newPrice;
notifyObservers(price);
}
}
public interface Observer{
public void update(Object args);
}
Is this(in brief) the right implementation of Observable? What else do I need to consider while building Observable class. Is there a way to automatically detect any chane in Observable instance or the inherited class has to explicitly call notifyObservers?
Please don't mind the syntax or minor error
Observerlook like? - Wim Deblauwe