next up previous
Next: Coding the View Class Up: How to Write a Previous: How to Write a

Warning

Most introductory books are written by authors who do not understand the model-view-controller pattern and 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 with 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 onerous abuse of the Java callback interface is implementing 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. 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 Eckel.


next up previous
Next: Coding the View Class Up: How to Write a Previous: How to Write a
Corky Cartwright 2004-02-05