Design Patterns in The Real World

This page contains supporting material for my O'Reilly video class .

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 developed this class (and wrote a book) to fix these problems. I'm a programmer, and I've written this material (both a book and video class) for programmers, 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 UML Quick Reference

My UML Quick Reference (online) presents the parts of UML that you're actually likely to use. UML has fallen out of favor as a design tool, in the Agile world at least. It is nonetheless an invaluable tool for talking about design to other architects (as we saw in class). A basic understanding of it is another tool in your communications arsenal. There are several UML books listed in the reading list below.

The Design Patterns Quick Reference

This reference (pdf) is an appendix from my book Holub On Patterns (below). It presents all of the patterns in a two-page format (if you print it in duplex mode, each pattern is represented on two facing pages.

This is very much a reference—nobody's going to learn the patterns by reading it—but it's a useful adjunct to the video class.

Holub on Patterns

This is my original book on Design Patterns, and it covers a lot of the same ground as the O'Reilly video class, but in more depth. Get the ebook from the publisher (Apress), or you can pick up a used copy on Amazon.

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 using the link at the top of this page.

Here are some patterns-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).

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

-Allen

Links

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 material. 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.

Catalogs

  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.
  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/class 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