Professional Documents
Culture Documents
add feature
1-inheritance with overriding
2-interface
//subject interface
public interface Subject{
//subject conceret
public class WheatherData implements Subject{
//data
private float tempeature;
private float humidity;
private float pressure;
private Array Observers;
//constructor
public WheatherObject(){
Observers = new Array();
}
//public interface
protected void registerObserver(Observer o){
Observers.add(o);
}
protected void removeObserver(Observer o){
int i = Observers.indexOf();
if(i>=){
Observers.remove(i);
}
}
protected void notifyObserver(){
for(int i=0; i<=Observers.size(); i++){
Observer observer = Observers.get(i);
observer.update(tempeature, humidity, pressure);
}
}
public void measurementChanged(){
notifyObserver();
}
public void setMeasurement(float temp, float humi, float pres){
this.tempeature = temp;
this.humidity = humi;
this.pressure = pres;
measurementChanged();
}
}
//observer interface
public interface Observer{ public void update(float temp, float humi, float
pres); }