Whew!

Though all this code seems complicated (because it is complicated), you don't write code like this very often. You use it a lot, however, and this class is pretty simple to use. Put a Collection into it, then use it like a Collection. Call visual_proxy() when you need to display a UI for the collection. That's it. With only a few wrappers like Bag, you can easily create visual proxies for many of the attributes of most abstraction-level classes.

Hopefully, I've also demonstrated the strengths of this architecture vis-a-vis eliminating the tight-coupling relationships inherent in many of the architectures that I've discussed in previous articles. A Bag provides a general, very loosely coupled mechanism for displaying object aggregations without knowing anything about what classes those objects instantiate.

Next month, I'll continue on the UI theme by discussing how a proxy can interact with the user via the application's main menu. In particular, I'll provide an implementation of a menu site class that defines the negotiation necessary for a proxy to get a seat at the menu bar. The proxy can then use this facility to let a user pick a particular look and feel by communicating directly to the proxy via a menu, rather than through the surrounding frame.

Allen Holub has been working in the computer
industry since 1979. He is widely published in magazines (Dr.
Dobb's Journal, Programmers Journal, Byte,
MSJ, among others). He has seven books to his credit, and
is currently working on an eighth that will present the complete
sources for a Java compiler written in Java. After eight years as a
C++ programmer, Allen abandoned C++ for Java in early 1996. He now
looks at C++ as a bad dream, the memory of which is mercifully
fading. He's been teaching programming (first C, then C++ and MFC,
now OO-Design and Java) both on his own and for the University of
California Berkeley Extension since 1982. Allen offers both public
classes and in-house training in Java and object-oriented design
topics. He also does object-oriented design consulting and contract
Java programming. Get information, and contact Allen, via his Web
site http://www.holub.com.

Learn more about this topic

A usual, the code to this month's article is available in the "Articles" section of my Web site. An index of all my previous JavaWorld articles (including the first two parts of the current series) can be found there as well. http://www.holub.com