Design patterns are standardized programming constructs used to solve recurring problems in software development. If you need to perform an operation on a list or tree structure, it’s logical that you’d want to traverse the list or tree in an iterative manner, performing the operation on each member. You could write your own code, but why reinvent the wheel when there’s an efficient, versatile, and extensible solution to your problem? With patterns, you can easily look up a general code implementation that will do the job for you. Software design patterns work with most Object Oriented languages. This book, Applied Java Patterns from Sun Microsystems Press, is tailored to Java patterns.

Applied Java Patterns

By Stephen Stelting and Olav Maassen
Prentice Hall
December 2001
574 pages
ISBN: 0-13-093538-7
Cover price: $44.99

A catalog of patterns
According to the authors, the book is intended to be “a pattern catalog for the Java programming language developers who understand at a basic level why patterns are a good idea, and are interested in applying them, but want a practical, hands-on guide to just how and why to use each individual pattern.” I’d say they met their goal.

The book is divided into three parts. The first presents each of the 32 patterns covered in great detail. The patterns are each divided into one of four classes: creational, behavioral, structural, and system. Thorough descriptions of the patterns in each class cover an introduction to the pattern, the purpose of the pattern, and applicable design situations. An implementation section covers pattern specifics. It’s followed by a discussion of the benefits and drawbacks of the implementation, as well as variants and related patterns. Finally, each pattern includes an actual code example.

The first part of the book definitely lives up to the authors’ goal of a complete, well-documented pattern catalog. Coverage is somewhat abstract and confusing at times, especially in the description sections for each pattern. The confusion is exaggerated by several typographical and layout errors. In one case, Example 3.10 of the Composite pattern is meant to provide the class description of the leaf nodes of the tree structure used, but it repeats the description of the interface the class implements. Fortunately, the coverage of each pattern seems sufficient to offset any confusion.

The examples given in the pattern catalog all center on a large and complex Personal Information Manager (PIM) application. This common frame of reference demonstrates the interrelations and interactions of the various patterns. It puts the example code in perspective without the need for additional application descriptions and background references. While more and different examples might showcase the patterns’ variety and versatility a little better, I believe that demonstrating how multiple patterns can be structured within the same application is more valuable in the end.

The Java API uses patterns
The second part of the book discusses the various Java APIs that make extensive use of patterns and how the patterns are used within them. As a developer, I found this less useful than the pattern reference provided in the first part, but it was quite interesting, both as an API user and a pattern user. The best part about this section is the additional examples of how the patterns can be used and partnered to form versatile, extensible, and robust solutions to complex software problems.

Plenty of examples
Finally, the third part of the book provides complete working examples of the patterns described in the first part. Many of these are expanded to include supporting patterns in a complete, useable framework. While the earlier examples only provided the classes and code segments necessary to understand the patterns, the examples in the third section include everything needed to implement the applications described. This section highlights the importance of knowing which patterns complement each other so that the whole is greater than the sum of its parts. An in-depth review of the examples admirably emphasizes this, which I consider one of the most important benefits of patterns.

Great for experienced Java developers
The material in this book is a bit too advanced for the novice Java programmer. The authors themselves state that the book is targeted at “experienced Java programmers who want to build better applications.” I believe the book lives up to its authors’ intentions. It‘s a wonderfully complete reference to most of the standard software design patterns specifically tailored to the Java language. It should be a welcome addition to the bookshelf of any Java developer interested in improving the quality of his or her code.