
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Core Implementation
|
427
By contrast, the delegation event model is typically appropriate when the granularity
of events matters (i.e., when events should correspond to individual methods rather
than a single update( ) method). Event granularity is desirable for event sources that
have a wide variety of unknown event listeners, as is often the case for publicly dis-
tributed components. For example, a SliderBar component might use the delegation
event model to broadcast onChanged( ), onDragged( ), and onReleased( ) events to
the world, but internally, it might maintain its own visual appearance using Observer
as part of MVC.
The Flow of Logic
Figure 19-1 shows the structure and logic flow of the delegation event model in dia-
grammatic form. The steps shown in the figure are as follows:
1. An instance of the event source (EventSourceClass) is created.
2. The event source creates and stores an instance of EventListenerList.
3. An instance of the event listener (EventListenerClass) is created and registers to
receive events from the event source.
4. The event listener is stored by the event source’s EventListenerList.
5. An event occurs and is broadcast by the event source as follows:
a. The event source creates an event object (EventObject) instance describing
the event.
b. The event source ...