DELEGATION EVENT MODEL

  • delegation event model is a specialized kind of Observer
  • description: "An event is propagated from a 'Source' object to a 'Listener' object by invoking a method on the listener and passing in the instance of the event subclass which defines the event type generated." (from Sun's Java AWT: Delegation Event Model)
  • called "delegation" event model because the event source "delegates" the processing of an event to a separate object (the event listener)
  • participants (based on Java's implementation):
    • event source
      • registers/unregisters event listener objects
      • broadcasts events to listeners (by invoking methods on them)
      • pushes an "event object" to listeners (by passing it to the event methods)
      • corresponding Observer pattern participant: Observable
    • event object
      • describes the event
      • provides methods to access information about the event (e.g., MouseEvent.getX())
      • passed to listener by event source
      • corresponding Observer pattern participant: Observer.update() method's infoObj parameter
    • event listener interface
      • defines agreed upon event methods (the event source invokes these on the listener object)
      • is implemented by event listener
      • corresponding Observer pattern participant: Observer.update() method
    • event listener object
      • registers with event source to receive events
      • reacts to events broadcast by event source
      • implements methods in event listener interface
      • corresponding Observer pattern participant: Observer


2 comments: