Event model

From Wikipedia, the free encyclopedia

The event model is a programming paradigm commonly used in building graphical user interfaces. A very common and very programmer-friendly variant is the delegate event model, which is provided by the most popular graphic frameworks.

[edit] Delegate event model

Delagate event model. Click me is the event source (a button in this example), and it contains a list of listeners.
Delagate event model. Click me is the event source (a button in this example), and it contains a list of listeners.

This model is based on three entities:

  • a control, which is the event source
  • consumers, also called listeners, that receive the events from the source
  • interfaces (in the broader meaning of the term) that describe the protocol by which every event is to be communicated

Furthermore the model requires that:

  • every listener must implement the interface for the event it wants to listen to
  • every listener must register with the source, to declare its desire to listen to some particular event
  • every time the source generates an event, it communicates it to the registered listeners, following the protocol of the interface
Languages