Model/View/Controller

Model/View/Controller


.

Model/View/Controller

Model/View/Controller

Model/View/Controller


.

Observer Pattern

Observer Pattern

Context

  1. An object, called the subject, is source of events
  2. One or more observer objects want to be notified when such an event occurs.

Solution

  1. Define an observer interface type. All concrete observers implement it.
  2. The subject maintains a collection of observers. 
  3. The subject supplies methods for attaching and detaching observers.
  4. Whenever an event occurs, the subject notifies all observers.

Observer Pattern

.

Names in Observer Pattern

Name in Design Pattern
Actual Name (Swing buttons)
Subject
JButton
Observer
ActionListener
ConcreteObserver
the class that implements the ActionListener interface type
attach()
addActionListener()
notify() actionPerformed()


Maintained by John Loomis, last updated 25 February 2007