Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesInside the Delegation Event Model


April 1997 / Reviews / Java Development Kit, Take Two / Inside the Delegation Event Model

JDK 1.1's version of AWT supports a new delegation model for handling events. The old model dealt with events in a hierarchical fashion. The AWT delivered an event to the target component (e.g., an ACTION_EVENT was delivered to the button that was clicked), which either handled the event or repeatedly passed it up the line to the containing objects. Ultimately, either a containing object handled (i.e., consumed) the event, or the event bubbled out the top of the containment hierarchy.

Programmers working in this model built applets with one of two event-handling architectures. In the first, they subclassed each potential target object (button, checkbox, and so forth) and overr ode the object's event-catching methods with code that responded appropriately to events. This architecture generated lots of subclasses as objects were individualized to their specific function. In the second architecture, programmers overrode the outermost containing object's handleEvent method and dealt with events through an often large and complex switch statement.

The new delegation model identifies those classes that can produce events (e.g., buttons, checkboxes, and text fields) as sources. Listener objects -- those that contain code to respond to events -- register themselves with source objects.

Furthermore, listener objects can register themselves according to the kinds of events they can handle. For example, a listener object might register itself to receive only action events (e.g., a button click) and would consequently not be bothered by adjustment events (e.g., changing the maximum value on a scroll bar). When a source object trig gers an event, that event is sent to all listener objects that are registered with that source to receive that kind of event.

Because code that handles an event is more directly connected to the event's source, the new model should result in more efficient programs. Additionally, new-model programs should be easier to understand; large, confusing switch statements are unnecessary.


Up to the Reviews section contentsGo to previous article: Inside the Delegation Event ModelSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network