Tags: observer pattern
*Observer Pattern*
Java calls this the Listener pattern.
It often occurs that one element of a design needs to take an action when another element of the design discovers that an event has occurred. Often we don't want the detector to know about the action taker. For example many different meters might want to know about changes in a sensor.
In practice the meters all implement a standard interface and register themselves with the sensor. When its state changes the sensor calls a method on each of the registered observers (listeners).
Last published: Thursday 5th January 2012
<<Previous Next>>