Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
In observer pattern, the objects that watch on the state of another object are called Observers and the object that is being watched is called Subject. The Subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
It is mainly used to implement distributed event handling systems.
Usage of Observer design pattern
Java Message Service (JMS) uses Observer pattern along with Mediator pattern to allow applications to subscribe and publish data to other applications.
MVC frameworks also use Observer pattern where Model is the Subject and Views are observers that can register to get notified of any change to the model.
The observer pattern is implemented in numerous programming libraries and systems, including almost all GUI toolkits.
Java provides inbuilt platform for implementing Observer pattern through java.util.Observable class and java.util.Observer interface.