next up previous
Next: 3.1.2.0.2 Coding the View Up: 3.1.2 How to Write Previous: 3.1.2 How to Write

3.1.2.0.1 Warning

Most introductory books are written by authors who do not understand the proper use of callbacks. Callbacks are not supported in C or C++ because there is no concept of procedures as data objects (simply passing a pointer to a procedure does NOT work!). As a result, textbook authors will a C/C++ background are accustomed to using ugly alternatives to callbacks which they continue to use in the context of Java. A common and particularly obnoxious abuse of the Java callback interface is to implement the requisite listener interfaces by methods in the main viewer class, which is typically a frame or an applet. This approach limits each event category to a single callback, e.g, one callback method for all buttons which is coded in the main viewer class.

This approach has four serious disadvantages.

Since the command pattern (procedures as data objects) completely eliminates this mess, the ``view class as listener'' approach to event processing is indefensible. Nevertheless, it is widely taught even by some reputed ``experts'' on Java programming (e.g., Cay Horstman in Core Java, pp. 316-325.) In fact, I am familiar with only one popular Java book that teaches good programming practice in conjunction with GUI programming, namely Thinking in Java by Bruce Eckels.


next up previous
Next: 3.1.2.0.2 Coding the View Up: 3.1.2 How to Write Previous: 3.1.2 How to Write
Corky Cartwright
2000-01-07