Code example for Observable

Methods: addObserver

0
    private float humidity;
    Observable observable;
     
    public void registerObserver(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    } 
     
    @Override 
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData){
            WeatherData wd = (WeatherData)o;
            this.temperature = wd.getTemperature();
            this.humidity = wd.getHumidity();
            display(); 
        } 
    } 
 
    @Override 
    public void display() { 
        StringBuilder sb = new StringBuilder();