Question: The live bourse tracking system codes you created for the observer pattern usage example are as follows, but they do not work. I think the

The live bourse tracking system codes you created for the observer pattern usage example are as follows, but they do not work. I think the main function is missing. Complete it so it works and draw the uml diagram of the final version of the code.
// Subject interface
public interface CurrencyRateTracker {
void registerObserver(Observer o);
void removeObserver(Observer o);
void notifyObservers();
}
// Concrete Subject
public class BourseRateTracker implements CurrencyRateTracker {
private List observers = new ArrayList<>();
private double usdTryRate;
public void setUsdTryRate(double rate){
this.usdTryRate = rate;
notifyObservers();
}
@Override
public void registerObserver(Observer o){
observers.add(o);
}
@Override
public void removeObserver(Observer o){
observers.remove(o);
}
@Override
public void notifyObservers(){
for (Observer observer : observers){
observer.update(usdTryRate);
}
}
}
// Observer interface
public interface Observer {
void update(double usdTryRate);
}
// Concrete Observer
public class CurrencyDisplay implements Observer {
@Override
public void update(double rate){
System.out.println("Updated USD/TRY Rate: "+ rate);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!