Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Observer Pattern - ConcreteSubject
public class ConcreteSubject1 implements Subject{
List<Observer> observers;
String message;
public ConcreteSubject1() {
this.observers = new ArrayList<>();
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
this.notifyObservers();
}
@Override
public void register(Observer o) {
observers.add(o);
}
@Override
public void unregister(Observer o) {
observers.remove(o);
}
@Override
public void notifyObservers() {
for(Observer o : observers) {
o.update(getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment