Observer Design Pattern
The Observer pattern is a behavioural design pattern in which an object, called the subject, keeps a list of dependents, called observers, and notifies them automatically whenever its state changes.
It decouples the object that changes from the objects that react, so new observers can be added without changing the subject. Event listeners in user interfaces, publish–subscribe messaging and reactive programming libraries are all based on this pattern.
interface Observer { void update(String news); }
class NewsAgency {
private final List<Observer> observers = new ArrayList<>();
void subscribe(Observer o) { observers.add(o); }
void publish(String news) { observers.forEach(o -> o.update(news)); }
}