Holub on Patterns:

Learning Design Patterns by Looking at Code

To be a good object-oriented designer, you have to know the design patterns cold, not just what they are, but how to apply them to solve real problems. Most books on the subject leave you in the lurch in the how-to-apply-patterns department, however. They catalog the patterns for you, but provide trivial examples that give you no real understanding of how the patterns work in the real world. Their examples don't show you the complex interactions between patterns, or the myriad ways that a pattern can be realized. Too many of the pattern books are filled with impenetrable academic prose that doesn't make the subject any easier.

I wrote this book to fix these problems. I'm a programmer, and I've written the book for programmers to read, centering the discussion around two non-trivial examples: a Game of Life implementation and a small embedded SQL interpreter. Taken together, these programs show you all of the "Gang of Four" design patterns in context. You can see how the patterns work and how they interact. You can see how they're actually used in nontrivial applications. I also discuss object-oriented-programming principles and how they apply to the patterns, so that you can understand why the patterns do what they do. The book also includes a design-patterns quick reference that you can use to refresh your memory as you learn the patterns.

You don't need to know anything about design patterns to read this book (though you do need to know Java). When you're done, you should understand the patterns thoroughly, and be able to apply them to your own work with ease.

Take the Class

Allen offers a two-day Agile Architecture. class that covers much of the material in this book, along with additional details on object-oriented architecture for Agile programming environments. This two-day seminar is base on analyzing real-world code, not trivial examples. We'll look at the Game of Life and SQL interpreter in Allen's book as well as a server-side UI framework (that's not in the book). This approach shows you how patterns actually appear in the real world, so gives you a real-world understanding that you can't get from the more typical catalog-of-patterns approach. You'll come out of this seminar understanding good OO architecture and knowing, not only what the patterns are, but how to apply them effectively.

Find more information at /training/oo.patterns.html.

Get The Source Code and Additional Material

The page is rather sparse right now, but I'll be augmenting it over time. To find out about changes to this page, bug-fix releases, and so on, you should subscribe to the newsletter. Here are some book-related links within the holub.com site:
  1. Get the source code for the Game of Life.
  2. Get the source code for the SQL interpreter (HolubSQL).
  3. Download the Static-Model and Design-Patterns Diagrams for the Game of Life (pdf/500 kb).
  4. Get a List of Listings, which references listing numbers and titles to page numbers.

If you find any bugs in the software, please report them to me.



The Hillside Design Patterns Home Page contains a wealth of information on design patterns (and vast numbers of links to other pattern-related sites).

Pattern Books and Articles

There are lots of other books on Patterns that nicely complement my book. Here's a list of good ones:

Applying Patterns

  1. Eric Gamma, JUnit, A Cook's Tour. This is an online article, not a book. It's a guided tour of the architecture of JUnit—Eric Gamma's unit-test platform. Gamma shows you how the design is built incrementally using a patterns approach. A great case study.
  2. Joshua Kerievsky Refactoring to Patterns. This book shows you how to correct common problems in badly done computer programs by systematically applying design patterns to the code. It identifies "Code Smells"---architectural defects---and takes you step by step through the process of correcting those defects using a design-patterns approach. I like the practical approach that the author takes.
  3. Buschmann, et al. Pattern-Oriented Software Architecture: A System of Patterns. This book introduces a few patterns new patterns, but more importantly, covers how patterns work together to form an overall architecture. In particular, they describe the "Presentation/Abstraction/Control" UI architecture, which is a vast improvement of Model/View/Controller.


  1. Gamma, Helm, Johnson, & Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software. The "Gang-of-Four Book." This is the book that started it all. It's a catalog of the patterns that I demonstrate in my book.
  2. John Vlissides, Pattern Hatching, Design Patterns Applied. A good complement to the Gang-of-Four book, covers material that probably should have been in the original book.
  3. Partha Kuchana Software Architecture Design Patterns in Java. This book is a Gang-of-Four style catalog of the Gang-of-Four design patterns. It's much more readable than the original, however, and the examples are in Java.
  4. Schmidt, et al. Pattern-Oriented Software Architecture vol. 2: Patterns for Concurrent and Networked Objects. A follow on to the Buschmann book mentioned above. Presents patterns for multithreading and concurrent applications.
  5. Coplein & Schmidt Ed., Pattern Languages of Program Design 1. The four PLOP books (this one and the next three in the list) catalog bunches of patterns not covered by the Gang of Four.
  6. Vlissides, Coplein, & Kerth Ed., Pattern Languages of Program Design 2.
  7. Martin, Riehle, & Buschmann, Pattern Languages of Program Design 3.
  8. Harrison, Foote, & Rohnert Ed. Pattern Languages of Program Design 4.
  9. Martin Fowler, et al. Patterns of Enterprise Application Architecture. Patterns associated with generic Enterprise applications, including database-related (Object-Relational) patterns and web patterns.
  10. Alur, Crupi, & Malks, Core J2EE Patterns: Best Practices and Design Strategies. Patterns associated with Java's "Enterprise Edition," particularly EJB architecture. To my mind, EJB is a failed technology. It's poorly conceived, poorly executed, and is a classic example of why design by committee fails to produce standards that are useful in the real world. This book's real value is in showing how a patterns approach can make a fundamentally flawed architecture usable.

UML Books

Martin Fowler's UML Distilled: A Brief Guide to the Standard Object Modeling Language (3d Ed.) Is a good introduction to UML.

My own UML Quick Reference is a good reference (if I do say so myself).

Craig Larman's Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process (2nd Ed.) is really a book about the entire OO-Design process. It shows you how UML is actually applied when building a real design. The book's only fault is that it's a little weak on the requirements-gathering side, but other books cover that subject.

Double-Checked Locking

I mention in the book that you shouldn't use the "double-checked locking" pattern to implement Singleton in a multithreaded scenario. Here are a few articles that explain why:

  1. Allen Holub, Warning! Threading in a Multiprocessor World.
  2. Brian Goetz, Double-checked locking: Clever, but broken.
  3. Bacon et al, The "Double-Checked Locking is Broken" Declaration