Award-winning Top 25 JUG!

Book Reviews

This book review was submitted by a DenverJUG member as part of the Book Review Program.

BOOK DETAILS

Holub on Patterns: Learning Design Patterns by Looking at Code
Author: Allen Holub
Publisher: Apress
Publish Date: September, 2004
Pages: 432
ISBN: 1-59059-388-x
Publisher's Book Description

Review Date: December, 2004
 

REVIEWER

Greg Baker

REVIEW

As stated in the preface, the topic of this book is straight forward: This is a book about programming in an object-oriented way and about how to use design patterns to solve commonplace problems in object-oriented systems.

Mr. Holub's treatment of this topic is both enjoyable and instructive.

The book's intended audience is software developers who want to create maintainable designs. The reader must be familiar with Java, including the use of anonymous inner classes. A familiarity with basic object-oriented concepts is desirable, although an uninitiated reader is given enough of the basics to proceed. Part of the final chapter deals with a SQL interpreter. If the reader is not familiar with recursive descent parsers, they will not understand this section; however, the section can easily be skipped without loss of continuity. Although Java is used throughout the book, the knowledge of design patterns can be applied to other languages as well.

The discussion begins with an introduction to patterns, focusing on what they are, why they exist and what they are not. Mr. Holub also weaves general object-oriented design philosophy into the discussion, providing the rationale for using design patterns as tools to better create and communicate designs.

The book is organized into four chapters and an appendix.

The first chapter introduces design patterns and their role in software design. It contains introductory material on object-oriented principles, as well as a discussion of how getter and setter methods tend to contradict the intent of object-oriented design.

The second chapter discusses circumstances in which implementation inheritance (use of the extends keyword in Java) can lead to an undesirable situation known as the fragile base class problem, and offers the use of interfaces as a superior alternative. It also introduces the Singleton and Abstract Factory patterns.

The third chapter steps through John Conway's Game of Life, implemented by Mr. Holub specifically for this book. The patterns introduced are Observer, Visitor, Composite, Facade, Bridge, Mediator, Prototype, Flyweight and Memento.

The fourth and final chapter steps through an embedded SQL interpreter, introducing the remainder of the Gang of Four (GoF) patterns -- Abstract Factory, Iterator, Builder, Command, Strategy, Decorator, Chain of Responsibility, Proxy, Interpreter, State and Adapter.

The appendix contains a catalog of the Gang of Four design patterns. It is organized similarly to the GoF book, but the information is more compact.

The final two chapters contain the meat of the discussion on design patterns. These two chapters comprise about 260 of the book's 400 pages. They are a refreshingly quick read, however, because a large component of these chapters is the source code of both programs. Mr. Holub included the full source code so readers can see the design patterns in full context. All too often, the "book-full-of-source-code" trick is used as a shortcut to generate page count; however, in this book, I actually appreciated and benefited from the completeness of the source code listings.

The difference between the GoF book and this book is that the GoF treats design patterns in a more academic manner, making it difficult to appreciate how they are combined in practice. Although Mr. Holub acknowledges the seminal contribution of the GoF to the field of design patterns, he also recognizes that it lacks the contextual emphasis needed to allow readers to appreciate how design patterns are applied in real programs. Mr. Holub's work fills this niche.

The book contains a fair number of errors -- a hallmark of being rushed to market. The text contains some invalid references to source code listings, making it more difficult than necessary to follow the logic. However, for the most part, the errors are minor, and are more of an annoyance than an impediment.

I had several notable take-aways from this book. First, Mr. Holub uses the term reification (literally, "to make real") to describe the activity of creating a design based on a design pattern. In using this uncommon word, he emphasizes that design patterns are not "instantiated" with source code templates. To think in terms of source code instantiation is to miss the whole point of design patterns -- to create a design that realizes some common intent or motive. He says he often receives emails from readers complaining that he has failed to follow the source code example prescribed in the Gang of Four book when using some pattern. To him, this demonstrates an essential lack of understanding that a design pattern can be realized through a virtually infinite variety of actual designs. What makes a design an instance of a design pattern is the realization of the pattern's intent. The book contains quite a few examples of different reifications for the same pattern.

My second takeaway was an emphasis on what Mr. Holub refers to as the prime directive of object-oriented design -- "Never ask an object for information that you need to do something; rather, ask the object that has the information to do the work for you." This is just a more user friendly way to say "data abstraction." Throughout the book, he points out how design patterns helped him adhere to this prime directive.

Finally, I enjoyed Mr. Holub's critique of various design choices of both Microsoft and Sun. He claims that the MFC and .NET frameworks are poor examples of object-oriented design, and were, in fact, purposefully designed as procedural frameworks to make them more palatable to non-OO programmers. These frameworks encourage and sometimes force programmers to disburse the implementation of a feature throughout the source code, making it less maintainable. Object Linking and Embedding, on the other hand, are much better examples of object-oriented thinking. As for Sun, Mr. Holub criticizes the use of the Factory Method pattern in the Swing JEditorPane class because it unnecessarily complicates the addition of new behavior. Other patterns, such as Strategy, would have been better choices. On the other hand, he praises the use of the Decorator pattern both in Java's I/O system and in adding thread safety to the Collections library.

All in all, I enjoyed Holub on Patterns. I would recommend it to anyone interested in design patterns. In fact, if I had to choose, I would recommend this book over the Gang of Four book. The appendix contains essentially the GoF information in a more compact form, plus the body of the book provides a much more practical, hands-on treatment of design patterns.