1.Introduction(介绍)
Designing object-oriented software is hard,and designing reusable object-oriented software is even harder.You must find pertinent objects, factor them into classes at the rightgranularity, define class interfaces and inheritance hierarchies, and establishkey relationships among them. Your design should be specific to the problem at hand but alsogeneral enough to address future problems and requirements. You also want toavoid redesign, or at least minimize it. Experienced object-oriented designerswill tell you that a reusable and flexible design is difficult if notimpossible to get "right" the first time. Before a design isfinished, they usually try to reuse it several times, modifying it each time
面向对象软件设计很难,面向对象的可重用的软件设计更难,.你需要发现相关的对象,在类中用准确的粒度把它分解,定义类的接口和继承的层次体系并且建立它们之间关键的关系。你需要对在手边的问题进行特殊的设计,并且大致上满足未来的地址问题和要求。你也想尽量避免重复设计,或者把它减少到最低。面向对象的软件设计经验会告诉你,如果没有在第一次时就得到正确的设计,那么实现可重复的灵活的设计是非常困难的,在你的设计完成之前,经常需要重新使用几次,修改它不完美的地方
Yet experienced object-oriented designersdo make good designs. Meanwhile new designers are overwhelmed by the optionsavailable and tend to fall back on non-object-oriented techniques they've usedbefore. It takes a long time for novices to learn what good object-oriented designis all about. Experienced designers evidently know something inexperienced ones don't. Whatis it?
现在面向对象的设计经验可以做出更好的设计,同时新的设计也被可用的选项和倾向于依靠过去依靠的非面向对象的技术,新手花费了很长时间去学习什么是优秀的面向对象设计,有经验的设计者显然知道一些没有经验的设计者所不知的东西,那么它是什么呢?
One thing expert designers know not to dois solve every problem from first principles. Rather, they reuse solutions thathave worked for them in the past. When they find a good solution, they use itagain and again. Such experience is part of what makes them experts.Consequently, you'll find recurring patterns of classes and communicatingobjects in many object-oriented systems. These patterns solve specific designproblems and make object-oriented designs more
flexible, elegant, and ultimately reusable.They help designers reuse successful designs by basing new designs on priorexperience. A designer who is familiar
with such patterns can apply themimmediately to design problems without having
to rediscover them.
从第一原则中,一个设计能手知道不去解决每一个问题,然而,他们重用那些在过去起效的解决方案,当他们发现更好的解决方案,他们会一遍又一遍的使用它,这样的经验是他们做专家的一部分,因此,在很多面向对象的系统里,你会发现很多再现的类和通信对象的模式,这些模式解决特殊的设计问题并且使面向对象设计更加灵活,简洁,成为最终的可重复的设计,他们在过去的经验上写出新的基础设计,这帮助设计者成功地重用设计,设计者熟悉这些模式,他们可以立即把模式应用于设计问题,而不需要再去重新发现它们!
An analogy will help illustrate the point Novelists and playwrightsrarely design theirplots from scratch Instead , they follow patterns like "Tragically Flawed Hero" (Macbeth, Hamlet, etc.) or"The Romantic Novel" (countless romance novels).In the same way,object-oriented designers follow patterns like "represent states withobjects" and "decorate objects so you can easily add/removefeatures." Once you know the pattern, a lot of designdecisions follow automatically.
一个类似的例子会说明这个问题。小说家或剧作家从草稿中极精彩的设计其情节,反倒由此产生了榜样例如”不幸的是有缺陷的英雄”或“浪漫主义小说”,面向对象设计继承模式,如“对象代表状态”,和“布置对象,因此你可以很容易的增加或移除这些特征”,一旦你知道这个模式,很多的设计决定会自动的继承过来!
We all know the value of design experience.How many times have you had design déjà-vu—that feeling that you've solved aproblem before but not knowing exactly where or how? If you could remember thedetails of the previous problem and howyou solved it, then you could reuse the experienceinstead of rediscovering it. However, we don't do a good job of recording experiencein software design for others to use.
我们都知道设计经验的价值,很多次你有似曾相识的设计,这种感觉是你在解决一个问题之前,但是并不知道在哪里产生,如何产生?如果你可以详细的记住以前的问题并且知道你是如何解决它的,之后你可以重用这些经验代替重新去发现它们。然而,我们不知道如何做好这些工作,去记录这些经验,在软件设计中给其他人用!
The purpose of this book is to record experience in designing object-oriented softwareas design patterns. Each design pattern systematically names, explains, and evaluates an importantand recurring design in object-oriented systems. Our goal is to capture designexperience in a form that people can use effectively.To this end we havedocumented some of the most important design patterns and present them as acatalog.
这本书的目的是记录在设计面向对象软件作为设计模式的经验。在面向对象系统里,每一个设计模式有重要的有组织的名字,注释,求某个值和再现的设计。我们的目的是以一种有效的形式去获得设计经验,在结束的时候我们有这些重要的设计样品的备份,作为一个模式样本再现它们。
Design patterns make it easier to reusesuccessful designs and architectures.Expressing proven techniques as designpatterns makes them more accessible to developers of new systems. Designpatterns help you choose design alternatives that make a system reusable andavoid alternatives that compromise reusability.Design patterns can even improvethe documentation and maintenance of existing systems by furnishing an explicitspecification of class and object interactions and their underlying intent. Put simply, design patterns help a designerget a design "right" faster.
设计模式使成功的重用设计和体系结构更容易.经验证明开发者设计样品的技巧使他们更容易获得新的系统。在系统重用时,设计模式帮助你选择设计体系结构,避免体系结构在重用时陷入危险。通过提供详述的类和对象互动的说明书,和他们潜在的想法,设计模式甚至可以更好地改善备份文件和维护已经存在的系统。说的更简单一点,设计模式可以帮助设计者更快得到完美的设计。
None of the design patterns in this bookdescribes new or unprovendesigns. We have included only designs that have beenapplied more than once in different systems. Most of these designs have neverbeen documented before. They are either part of the folklore of theobject-oriented community or are elements of some successful object-orientedsystems—neither of which is easy for novice designers to learn from. Soalthough these designs aren't new, we capture them in a new and accessible way: as a catalog of designpatterns having a consistent format.
在这本书里没有描述一个新的或者未被证实多的设计模式。只含有一个在不同的系统里不止被应用一次的设计。在这之前这些设计从来没有备份,它们要么是面向对象生态的一部分,要么是一些成功的面向对象系统里的基础元素。这两者使设计新手不容易从中学习。尽管这些设计不是新的,我们获得它们用新的访问方式,使产品样本的设计模式有一致的格式,
Despite the book's size, the designpatterns in it capture only a fraction of what an expert might know. It doesn'thave any patterns dealing with concurrency or distributed programming orreal-time programming. It doesn't have any application domain-specificpatterns. It doesn't tell you how to build user interfaces, how to write devicedrivers,, or how touse an object-oriented database Each of these areas has its own patterns,,and it would be worthwhile forsomeone to catalog those too.
不管这本书的大小,设计样本仅仅是一个专家所知道的的一部分,.它没有任何处理并发性或分布式或实时的程序的样本,它没有任何具有领域特殊性的样本,它没有告诉你如何去创建用户界面,如何去写设备驱动程序,.如何去写面向对象数据库,在这个领域的每一个人都有自己的产品模式,一些人去花时间做产品样本是值得的。