Intent

One object changes state, all of its dependents are updated automatically.

Where to use & benefits

Structure


Participants

Subject  (Not used)
knows its observers. Any number of Observer objects may observe a subject and provides an interface for attaching and detaching Observer objects.

ConcreteSubject  (java.awt.Button)
stores state of interest to ConcreteObserver and sends a notification to its observers when its state changes

Observer  (java.awt.event.ActionListner)
defines an updating interface for objects that should be notified of changes in a subject.

ConcreteObserver  (MainApplet)

Example

In the demonstration application, the applet GUI components (Button, List) are register with the ActionListner interface to handle the user events. When user performs operation (like clicking the button), the respective method actionPerformed(ActionEvent evt) is invoked in the MainApplet class.

Class Diagram


Source Code Links