📄 chap6.htm
字号:
<P>In fact, noticing that something is a pattern is the easy part.All four of us are actively working on building object-orientedsystems, and we've found that it's easy to spot patterns when youlook at enough systems. But <EM>finding</EM> patterns is mucheasier than <EM>describing</EM> them.</P><A NAME="auto1018"></A><P>If you build systems and then reflect on what you build, you will seepatterns in what you do. But it's hard to describe patterns so thatpeople who don't know them will understand them and realize why theyare important. Experts immediately recognized the value of thecatalog in its early stages. But the only ones who could understandthe patterns were those who had already used them.</P><A NAME="auto1019"></A><P>Since one of the main purposes of the book was to teachobject-oriented design to new designers, we knew we had to improve thecatalog. We expanded the average size of a pattern from less than 2to more than 10 pages by including a detailed motivating example and samplecode. We also started examining the trade-offs and the various waysof implementing the pattern. This made the patterns easier to learn.</P><A NAME="auto1020"></A><P>Another important change over the past year has been a greater emphasis onthe problem that a pattern solves. It's easiest to see a pattern as asolution, as a technique that can be adapted and reused. It's harderto see when it is <EM>appropriate</EM>—to characterize the problems itsolves and the context in which it's the best solution. In general,it's easier to see <EM>what</EM> someone is doing than to know <EM>why</EM>,and the "why" for a pattern is the problem it solves. Knowingthe purpose of a pattern is important too, because it helps us choosepatterns to apply. It also helps us understand the design of existingsystems. A pattern author must determine and characterize the problemthat the pattern solves, even if you have to do it after you'vediscovered its solution.</P><A NAME="sec6-3"></A><H2><A HREF="#sec6-4"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: An Invitation"></A>The Pattern Community</H2><A NAME="auto1021"></A><P>We aren't the only ones interested in writing books that catalog thepatterns experts use. We are a part of a larger community interestedin patterns in general and software-related patterns in particular.Christopher Alexander is the architect who first studied patterns inbuildings and communities and developed a "pattern language" forgenerating them. His work has inspired us time and again. So it'sfitting and worthwhile to compare our work to his. Then we'll look atothers' work in software-related patterns.</P><A NAME="alexander"></A><H3>Alexander's Pattern Languages</H3><A NAME="auto1022"></A><P>There are many ways in which our work is like Alexander's. Both arebased on observing existing systems and looking for patterns in them.Both have templates for describing patterns (although our templates arequite different). Both rely on natural language and lots of examplesto describe patterns rather than formal languages, and both giverationales for each pattern.</P><A NAME="auto1023"></A><P>But there are just as many ways in which our works are different:</P><OL><A NAME="auto1024"></A><LI>People have been making buildings for thousands of years, and thereare many classic examples to draw upon. We have been making softwaresystems for a relatively short time, and few are considered classics.</LI><A NAME="auto1025"></A><P></P><A NAME="auto1026"></A><LI>Alexander gives an order in which his patterns should be used; we havenot.</LI><A NAME="auto1027"></A><P></P><A NAME="auto1028"></A><LI>Alexander's patterns emphasize the problems they address, whereasdesign patterns describe the solutions in more detail.</LI><A NAME="auto1029"></A><P></P><A NAME="auto1030"></A><LI>Alexander claims his patterns will generate complete buildings. We donot claim that our patterns will generate complete programs.</LI></OL><A NAME="design-poetry"></A><P>When Alexander claims you can design a house simply by applying hispatterns one after another, he has goals similar to those ofobject-oriented design methodologists who give step-by-step rules fordesign. Alexander doesn't deny the need for creativity; some of hispatterns require understanding the living habits of the people whowill use the building, and his belief in the "poetry" of designimplies a level of expertise beyond the pattern languageitself.<A NAME="fn1"></A><A HREF="#footnote1"><SUP>1</SUP></A>But his description of how patternsgenerate designs implies that a pattern language can make the designprocess deterministic and repeatable.</P><A NAME="auto1031"></A><P>The Alexandrian point of view has helped us focus on designtrade-offs—the different "forces" that help shape a design. Hisinfluence made us work harder to understand the applicability andconsequences of our patterns. It also kept us from worrying aboutdefining a formal representation of patterns. Although such arepresentation might make automating patterns possible, at this stageit's more important to explore the space of design patterns than toformalize it.</P><A NAME="auto1032"></A><P>From Alexander's point of view, the patterns in this book do not forma pattern language. Given the variety of software systems that peoplebuild, it's hard to see how we could provide a "complete" set ofpatterns, one that offers step-by-step instructions for designing anapplication. We can do that for certain classes of applications, suchas report-writing or making a forms-entry system. But our catalog isjust a collection of related patterns; we can't pretend it's a patternlanguage.</P><A NAME="auto1033"></A><P>In fact, we think it's unlikely that there will <EM>ever</EM> be acomplete pattern language for software. But it's certainly possibleto make one that is <EM>more</EM> complete. Additions would have toinclude frameworks and how to use them [<A HREF="bibfs.htm#hotdraw" TARGET="_mainDisplayFrame">Joh92</A>], patterns foruser interface design [<A HREF="bibfs.htm#beck-johnson_ecoop94" TARGET="_mainDisplayFrame">BJ94</A>], analysispatterns [<A HREF="bibfs.htm#coad_patterns" TARGET="_mainDisplayFrame">Coa92</A>], and all the other aspects of developingsoftware. Design patterns are just a part of a larger patternlanguage for software.</P><A NAME="patt-lang-of-prog"></A><H3>Patterns in Software</H3><A NAME="anderson"></A><P>Our first collective experience in the study of software architecturewas at an OOPSLA '91 workshop led by Bruce Anderson. Theworkshop was dedicated to developing a handbook for softwarearchitects. (Judging from this book, we suspect "architectureencyclopedia" will be a more appropriate name than "architecturehandbook.") That first workshop has led to a series of meetings, themost recent of which being the first conference on Pattern Languagesof Programs held in August 1994. This has created a community ofpeople interested in documenting software expertise.</P><A NAME="knuth"></A><P>Of course, others have had this goal as well. Donald Knuth's <EM>TheArt of Computer Programming</EM> [<A HREF="bibfs.htm#knuth_art" TARGET="_mainDisplayFrame">Knu73</A>] was one of the firstattempts to catalog software knowledge, though he focused ondescribing algorithms. Even so, the task proved too great tofinish. The <EM>Graphics Gems</EM>series [<A HREF="bibfs.htm#graphicsGems1" TARGET="_mainDisplayFrame">Gla90</A>, <A HREF="bibfs.htm#graphicsGems2" TARGET="_mainDisplayFrame">Arv91</A>, <A HREF="bibfs.htm#graphicsGems3" TARGET="_mainDisplayFrame">Kir92</A>] is anothercatalog of design knowledge, though it too tends to focus onalgorithms. The Domain Specific Software Architecture programsponsored by the U.S. Department of Defense [<A HREF="bibfs.htm#dod_dssap" TARGET="_mainDisplayFrame">GM92</A>]concentrates on gathering architectural information. Theknowledge-based software engineering community tries to representsoftware-related knowledge in general. There are many other groupswith goals at least a little like ours.</P><A NAME="auto1034"></A><P>James Coplien's <EM>Advanced C++: Programming Styles andIdioms</EM> [<A HREF="bibfs.htm#coplien_idioms" TARGET="_mainDisplayFrame">Cop92</A>] has influenced us, too. The patterns inhis book tend to be more C++-specific than our design patterns, andhis book contains lots of lower-level patterns as well. But there issome overlap, as we point out in our patterns. Jim has been active inthe pattern community. He's currently working on patterns thatdescribe people's roles in software development organizations.</P><A NAME="kentbeck"></A><P>There are a lot of other places in which to find descriptionsof patterns. Kent Beck was one of the first people in the softwarecommunity to advocate Christopher Alexander's work. In 1993 hestarted writing a column in <EM>The Smalltalk Report</EM> onSmalltalk patterns. Peter Coad has also been collecting patternsfor some time. His paper on patterns seems to us to contain mostlyanalysis patterns [<A HREF="bibfs.htm#coad_patterns" TARGET="_mainDisplayFrame">Coa92</A>];we haven't seen his latest patterns, though we know he is stillworking on them. We've heard of several books on patterns thatare in the works, but we haven't seen any of them, either. All wecan do is let you know they're coming. One of these books will befrom the Pattern Languages of Programs conference.</P><A NAME="sec6-4"></A><H2><A HREF="#sec6-5"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: A Parting Thought"></A>An Invitation</H2><A NAME="auto1035"></A><P>What can you do if you are interested in patterns? First, use themand look for other patterns that fit the way you design. A lot of books and articles about patterns will be coming outin the next few years,so there will be plenty of sources for new patterns. Develop yourvocabulary of patterns, and use it. Use it when you talk with otherpeople about your designs. Use it when you think and write about them.</P><A NAME="auto1036"></A><P>Second, be a critical consumer. The design pattern catalog is theresult of hard work, not just ours but that of dozens of reviewers whogave us feedback. If you spot a problem or believe moreexplanation is needed, contact us. The same goes for any other catalog ofpatterns: Give the authors feedback! One of the great things aboutpatterns is that they move design decisions out of the realm of vagueintuition. They let authors be explicit about the trade-offs theymake. This makes it easier to see what is wrong with their patternsand to argue with them. Take advantage of that.</P><A NAME="auto1037"></A><P>Third, look for patterns you use, and write them down. Make them apart of your documentation. Show them to other people. You don'thave to be in a research lab to find patterns. In fact, findingrelevant patterns is nearly impossible if you don't have practicalexperience. Feel free to write your own catalog of patterns...butmake sure someone else helps you beat them into shape!</P><A NAME="design-density"></A><A NAME="sec6-5"></A><H2><A HREF="#last"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: navigation"></A>A Parting Thought</H2><A NAME="auto1038"></A><P>The best designs will use many design patterns that dovetail andintertwine to produce a greater whole. As Christopher Alexander says:</P><BLOCKQUOTE>It is possible to make buildings by stringing together patterns, in arather loose way. A building made like this, is an assembly ofpatterns. It is not dense. It is not profound. But it is also possibleto put patterns together in such a way that many patterns overlap inthe same physical space: the building is very dense; it has manymeanings captured in a small space; and through this density, itbecomes profound.</BLOCKQUOTE><P ALIGN=RIGHT><CITE>A Pattern Language</CITE> [<A HREF="bibfs.htm#Alexander_pl" TARGET="_mainDisplayFrame">AIX+77</A>, page <EM>xli</EM>]</P><A NAME="last"></A><P><A HREF="#top"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="chapAfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif" ALIGN=TOP BORDER=0></A> <A HREF="chapAfs.htm" TARGET="_mainDisplayFrame">Glossary</A><BR><A HREF="disc5fs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif" ALIGN=TOP BORDER=0></A> <A HREF="disc5fs.htm" TARGET="_mainDisplayFrame">Discussion of Behavioral Patterns</A></P><HR><A NAME="footnote1"></A><P><SUP>1</SUP>See "The poetry of thelanguage" [<A HREF="bibfs.htm#Alexander_pl" TARGET="_mainDisplayFrame">AIS+77</A>].</P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -