The prime benefit of the Observer pattern is that objects can vary independent of each other.
In particular, you can add or delete different
objects as needed.
objects may be of the same or different classes as long as they implement the same
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents,
called observers, and notifies them automatically of any state changes, usually by calling one of its methods.
The observer pattern is mainly used to implement distributed event handling systems.
You should be aware of a few potential pitfalls when implementing the Observer pattern:
Generally, you need to make sure that the change of state is complete and that the object has a consistent state before notifying observers of the change.
Be clear about whether the order in which
Observer objects are notified is or is not predictable.
Do not let an
Observer register itself twice with the same
Observed object unless you are sure that is what it means to do.