Table of Contents
Preface to Book
Foreword
Guide to Readers
Introduction
• What Is a Design Pattern?
• Design Patterns in Smalltalk MVC
• Describing Design Patterns
• The Catalog of Design Patterns
• Organizing the Catalog
• How Design Patterns Solve Design Problems
• How to Select a Design Pattern
• How to Use a Design Pattern
A Case Study: Designing a Document Editor
• Design Problems
• Document Structure
• Formatting
• Embellishing the User Interface
•
•
• User Operations
•
•
Spelling Checking and Hyphenation
Summary
Supporting Multiple Look-and-Feel Standards
Supporting Multiple Window Systems
Design Pattern Catalog
Creational Patterns
• Abstract Factory
• Builder
• Factory Method
• Prototype
•
Singleton
• Discussion of Creational Patterns
Structural Patterns
• Adapter
• Bridge
• Composite
• Decorator
• Facade
• Flyweight
• Proxy
• Discussion of Structural Patterns
Behavioral Patterns
• Chain of Responsibility
• Command
•
Interpreter
•
Iterator
• Mediator
• Memento
• Observer
•
•
• Template Method
• Visitor
• Discussion of Behavioral Patterns
State
Strategy
Conclusion
• What to Expect from Design Patterns
• A Brief History
• The Pattern Community
• An Invitation
• A Parting Thought
Glossary
Guide to Notation
• Class Diagram
• Object Diagram
•
Interaction Diagram
Foundation Classes
Iterator
• List
•
• ListIterator
• Point
• Rect
Bibliography
Index
Preface to Book
This book isn't an introduction to object-oriented technology or design. Many
books already do a good job of that. This book assumes you are reasonably
proficient in at least one object-oriented programming language, and you
should have some experience in object-oriented design as well. You
definitely shouldn't have to rush to the nearest dictionary the moment we
mention "types" and "polymorphism," or "interface" as opposed to
"implementation" inheritance.
On the other hand, this isn't an advanced technical treatise either. It's a book
of design patterns that describes simple and elegant solutions to specific
problems in object-oriented software design. Design patterns capture
solutions that have developed and evolved over time. Hence they aren't the
designs people tend to generate initially. They reflect untold redesign and
recoding as developers have struggled for greater reuse and flexibility in their
software. Design patterns capture these solutions in a succinct and easily
applied form.
The design patterns require neither unusual language features nor amazing
programming tricks with which to astound your friends and managers. All can
be implemented in standard object-oriented languages, though they might
take a little more work than ad hoc solutions. But the extra effort invariably
pays dividends in increased flexibility and reusability.
Once you understand the design patterns and have had an "Aha!" (and not just
a "Huh?") experience with them, you won't ever think about object-oriented
design in the same way. You'll have insights that can make your own designs
more flexible, modular, reusable, and understandable—which is why you're
interested in object-oriented technology in the first place, right?
A word of warning and encouragement: Don't worry if you don't understand
this book completely on the first reading. We didn't understand it all on the
first writing! Remember that this isn't a book to read once and put on a shelf.
We hope you'll find yourself referring to it again and again for design insights
and for inspiration.
This book has had a long gestation. It has seen four countries, three of its
authors' marriages, and the birth of two (unrelated) offspring. Many people
have had a part in its development. Special thanks are due Bruce Anderson,
Kent Beck, and André Weinand for their inspiration and advice. We also thank
those who reviewed drafts of the manuscript: Roger Bielefeld, Grady Booch,
Tom Cargill, Marshall Cline, Ralph Hyre, Brian Kernighan, Thomas Laliberty,
Mark Lorenz, Arthur Riel, Doug Schmidt, Clovis Tondo, Steve Vinoski, and
Rebecca Wirfs-Brock. We are also grateful to the team at Addison-Wesley for
their help and patience: Kate Habib, Tiffany Moore, Lisa Raffaele, Pradeepa
Siva, and John Wait. Special thanks to Carl Kessler, Danny Sabbah, and Mark
Wegman at IBM Research for their unflagging support of this work.
Last but certainly not least, we thank everyone on the Internet and points
beyond who commented on versions of the patterns, offered encouraging
words, and told us that what we were doing was worthwhile. These people
include but are not limited to Jon Avotins, Steve Berczuk, Julian Berdych,
Matthias Bohlen, John Brant, Allan Clarke, Paul Chisholm, Jens Coldewey,
Dave Collins, Jim Coplien, Don Dwiggins, Gabriele Elia, Doug Felt, Brian Foote,
Denis Fortin, Ward Harold, Hermann Hueni, Nayeem Islam, Bikramjit Kalra,
Paul Keefer, Thomas Kofler, Doug Lea, Dan LaLiberte, James Long, Ann
Louise Luu, Pundi Madhavan, Brian Marick, Robert Martin, Dave McComb, Carl
McConnell, Christine Mingins, Hanspeter Mössenböck, Eric Newton, Marianne
Ozkan, Roxsan Payette, Larry Podmolik, George Radin, Sita Ramakrishnan,
Russ Ramirez, Alexander Ran, Dirk Riehle, Bryan Rosenburg, Aamod Sane,
Duri Schmidt, Robert Seidl, Xin Shu, and Bill Walker.
We don't consider this collection of design patterns complete and static; it's
more a recording of our current thoughts on design. We welcome comments
on it, whether criticisms of our examples, references and known uses we've
missed, or design patterns we should have included. You can write us care of
Addison-Wesley, or send electronic mail to design-patterns@cs.uiuc.edu. You
can also obtain softcopy for the code in the Sample Code sections by sending
the message "send design pattern source" to
design-patterns-source@cs.uiuc.edu. And now there's a Web page at
http://st-www.cs.uiuc.edu/users/patterns/DPBook/DPBook.html for
late-breaking information and updates.
Mountain View, California
Montreal, Quebec
Urbana, Illinois
Hawthorne, New York
August 1994
E.G.
R.H.
R.J.
J.V.
Foreword
Consider the work of a future software archeologist, tracing the history of
computing. The fossil record will likely show clear strata: here is a layer
formed of assembly language artifacts, there is a layer populated with the
skeletons of high order programming languages (with certain calcified legacy
parts probably still showing some signs of life). Each such layer will be
intersected with the imprint of other factors that have shaped the software
landscape: components, residue from the great operating system and
browser wars, methods, processes, tools. Each line in this strata marks a
definitive event: below that line, computing was this way; above that line,
the art of computing had changed.
Design Patterns draws such a line of demarcation; this is a work that
represents a change in the practice of computing. Erich, Richard, Ralph, and
John present a compelling case for the importance of patterns in crafting
complex systems. Additionally, they give us a language of common patterns
that can be used in a variety of domains.
The impact of this work cannot be overstated. As I travel about the world
working with projects of varying domains and complexities, it is uncommon
for me to encounter developers who have not at least heard of the patterns
movement. In the more successful projects, it is quite common to see many
of these design patterns actually used.
With this book, the Gang of Four have made a seminal contribution to
software engineering. There is much to learned from them, and much to be
actively applied.
Grady Booch
Chief Scientist, Rational Software Corporation