Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Subject {
private String status;
private List<Observer> observers = new ArrayList<Observer>();
public String getStatus() {
return status;
}
public void setStatus(String status) {
System.out.println("changing the status to [" + status + "] ");
this.status = status;
this.notifyObservers();
}
public void subscribe(Observer observer) {
observers.add(observer);
}
public void unsubscribe(Observer observer) {
observers.remove(observer);
}
private void notifyObservers() {
System.out.println("notifying observers");
observers.stream().forEach((observer) -> {
observer.receiveUpdate(this);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.