SE450: Observer Pattern [21/72] Previous pageContentsNext page

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.

Previous pageContentsNext page