Google

Friday, June 03, 2005

How to Use Design Patterns

Eric Gamma interviewed by Bill Venners:

Design Patterns help people learn object-oriented thinking: leverage polymorphism, design for composition, delegation, balance responsibilities, provide pluggable behavior. They help you where you need more flexibility, to encapsulate an abstraction, to make code less coupled, preserve layers, avoid up calls and circular dependencies.

You only appreciate a pattern once you have felt this design pain (for example duplicated code). Do not start immediately throwing patterns into a design, but use them as you go and understand more of the problem. Trying to use all the patterns is a bad thing. When you have a code smell go to the patterns toolbox to find a solution. The goal is a clean, easy to understand API, not to win an I-used-the-most-patterns contest.

When you really need extensibility, then patterns provide you with a way to achieve it. But when you don't need it, you should keep your design simple and not add unnecessary levels of indirection.

Pattern density: core abstractions, and around that several other emerging design points, which in turn are materialized by pattern instances.

Being fluent in patterns conversation goes really fast, enabling a high-velocity design. Patterns give us a language to talk about design.

micro-architectures: recurring design structures that give you properties like extensibility, decoupling, and last but not least, elegance.

For a good example of pattern usage see JUnit: A Cook's Tour, an article by Erich Gamma and Kent Beck, that walks you through the design of JUnit by "starting with nothing and applying patterns, one after another, until you have the architecture of the system."

Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. The authoritive guide and without doubt one of the most influential books on software development of the past decade.


Head First Design Patterns, by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra. A recent book that communicates the essence of design patterns in a novel and highly visual way.

0 Comments:

Post a Comment

Read more about Software Quality at the <<Software Quality Weblog Home