Most Read Latest News Blog Resources

Reading About Design Patterns




November 15, 2004 — 
Good software must be designed before it’s built. Code that’s written without the benefit of design takes two to three times longer to write than necessary, and is usually considerably more buggy as well. This isn’t to say that all of the design for a large program must be complete before you write a line of code—the agile methodologies all depend on an incremental design process that parallels development.

But learning design is tough. It takes as long to learn to design well as it does to learn to code well; and the subject is, if anything, more difficult. Simply working with code libraries, or mastering the design of a couple of large systems, teaches you almost nothing about design itself. To make matters worse, it’s not really possible to write a single book that covers the entire subject of software design. It’s just too large a subject.

One essential topic in the design curriculum is design patterns. The notion of a design pattern is that certain patterns—systems of similar solutions to similar problems—emerge when you look at a lot of code. Good programmers who write quality code tend to gravitate to similar solutions to common problems. Once you recognize a “pattern” in these solutions, you can catalog the pattern. If you carry around such a catalog in your head (and you really need to know the patterns that well to apply them effectively), then you can apply these known-to-be-good solutions to your own programming problems right off the bat.

The result is better quality code that goes together faster. To my mind, design patterns are as central to the profession of programming as algorithms, data structures and the programming languages themselves. You’re not a true professional unless you know them cold.

Unfortunately, design patterns are a subject where the can’t-learn-it-from-a-book situation has been particularly pronounced. Most books on design patterns, including the original Gang of Four book—“Design Patterns,” by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, published in 1995—take a catalog approach to the subject. The patterns are presented in isolation, one at a time. That never happens in the real world where they’re all jumbled together.

The catalog approach leads you to believe that a pattern has a specific structure, representable with a single UML diagram, and that there’s only one “correct” implementation of the pattern. None of these beliefs is true. You can’t cut and paste a pattern. More to the point, unless you’re an experienced programmer who has already stumbled on the patterns the hard way, the catalog-style books tend to be incomprehensible.

To solve this problem, I’d like to bring two brand-new books to your attention. The common thread in these books is that they’re centered on code, not on an academic taxonomy.

The first book is Joshua Kerievsky’s “Refactoring to Patterns,” published in August. Kerievsky teaches patterns by showing you how they can be applied to existing, suboptimal Java code. That is, he starts out with programs that are essentially unstructured, and shows you how to improve the quality of the programs (to refactor them) by rewriting them in terms of the Gang of Four patterns.

He identifies 13 bad “smells” in code (duplicate code, too-large classes, too many switch statements, etc.). He then explains how to apply specific patterns to fix the problem, taking you step by step through the refactoring process. Kerievsky’s approach is eminently practical and solidly grounded in real work that all of us have to do at one point or another, which is to make bad code better so that it can be maintained.

The second book of interest, I humbly submit, is the modestly named “Holub on Patterns: Learning Design Patterns by Looking at Code,” which came out in September. My approach also centers around real programs, not artificial examples.

The book teaches patterns by analyzing two nontrivial programs: implementations of Conway’s “Game of Life,” and also an embedded SQL interpreter with a JDBC wrapper. The two programs together show you at least one example of every one of the Gang of Four patterns. You’ll see the patterns actually applied in context. More to the point, you’ll see how the patterns interact and complement one another—something that you’ll never see in a catalog.

I’ve set up a design patterns page at www.holub.com/goodies/patterns, which has links to useful patterns sites as well as a design patterns reading list. (You also can get the code from the book from that page.)

Knowing design patterns is an essential part of being a good programmer, and these two books, grounded in real code as they are, should help you understand patterns thoroughly.

Allen Holub is an architect, consultant and instructor in C/C++, Java and OO Design. Reach him at www.holub.com.


Share this link: http://www.sdtimes.com/link/28242
 

Add comment


Name*
Email*  
Country     


  • Comment
  • Preview
Loading



 
 
 
 
News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 
Download Current Issue
ISSUE 3/15/2010 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
blogs tab
Google Code turns 5
Google Code Turns 5, and adds a Paxos Algorithm to make the system more stable and reliable.
03/17/2010 11:16 AM EST

Test your Visual Studio 2010 know-how
Microsoft is offering free beta certification exams for Visual Studio 2010.
03/17/2010 11:08 AM EST

Microsoft lifts the hood on IE9
Microsoft is previewing IE9.
03/16/2010 01:10 PM EST

 

Events calendar tab
3/22/2010 to 3/25/2010
Santa Clara, Calif.
The Eclipse Foundation

4/12/2010 to 4/14/2010
Las Vegas
Penton Media

4/12/2010 to 4/15/2010
Santa Clara, Calif.
O'Reilly Media

4/19/2010
New York City
Flagg Management

4/25/2010 to 4/28/2010
Overland Park, Kans.
IIUG