FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Design_Patterns

Design Patterns

Elements of Reusable {{nobr|Object-Oriented}} Software"},"image":{"wt":"Design Patterns cover.jpg"},"author":{"wt":"{{unbulleted list|[[Erich Gamma]]|[[Richard Helm]]|[[Ralph Johnson (computer scientist)|Ralph Johnson]]|[[John Vlissides]]}}"},"illustrator":{"wt":""},"cover_artist":{"wt":""},"publication_place":{"wt":"United States"},"subject":{"wt":"[[Design pattern]]s, [[software engineering]], [[object-oriented programming]]"},"genre":{"wt":""},"publisher":{"wt":"[[Addison-Wesley]]"},"publication_date":{"wt":"1994"},"media_type":{"wt":""},"pages":{"wt":"395"},"isbn":{"wt":"0-201-63361-2"},"oclc":{"wt":"31171684"},"dewey":{"wt":"005.1/2 20"},"congress":{"wt":"QA76.64 .D47 1995"}},"i":0}}]}'>
Design Patterns:
Elements of Reusable Object-Oriented Software
Author
SubjectDesign patterns, software engineering, object-oriented programming
PublisherAddison-Wesley
Publication date1994
Publication placeUnited States
Pages395
ISBN0-201-63361-2
Online Computer Library Center number</span>"}]]}'>OCLC31171684
Dewey Decimal005.1/2 20
Library of Congress Classification</span>"}]]}'>LC ClassQA76.64 .D47 1995

Design Patterns: Elements of Reusable Object-Oriented Software (1994) is a software engineering book describing software design patterns. The book was written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, with a foreword by Grady Booch. The book is divided into two parts, with the first two chapters exploring the capabilities and pitfalls of object-oriented programming, and the remaining chapters describing 23 classic software design patterns. The book includes examples in C++ and Smalltalk.

It has been influential to the field of software engineering and is regarded as an important source for object-oriented design theory and practice. More than 500,000 copies have been sold in English and in 13 other languages. Both the authors and the book are often referred to as the Gang of Four (GoF).

Chapter 1 is a discussion of object-oriented design techniques, based on the authors' experience, which they believe would lead to good object-oriented software design, including:

The authors claim the following as advantages of interfaces over implementation:

Use of an interface also leads to dynamic binding and polymorphism, which are central features of object-oriented programming.

The authors refer to inheritance as white-box reuse, with white-box referring to visibility, because the internals of parent classes are often visible to subclasses. In contrast, the authors refer to object composition (in which objects with well-defined interfaces are used dynamically at runtime by objects obtaining references to other objects) as black-box reuse because no internal details of composed objects need be visible in the code using them.

The authors discuss the tension between inheritance and encapsulation at length and state that in their experience, designers overuse inheritance (Gang of Four 1995:20). The danger is stated as follows:

"Because inheritance exposes a subclass to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'". (Gang of Four 1995:19)

They warn that the implementation of a subclass can become so bound up with the implementation of its parent class that any change in the parent's implementation will force the subclass to change. Furthermore, they claim that a way to avoid this is to inherit only from abstract classes—but then, they point out that there is minimal code reuse.

Using inheritance is recommended mainly when adding to the functionality of existing components, reusing most of the old code and adding relatively small amounts of new code.

To the authors, 'delegation' is an extreme form of object composition that can always be used to replace inheritance. Delegation involves two objects: a 'sender' passes itself to a 'delegate' to let the delegate refer to the sender. Thus the link between two parts of a system are established only at runtime, not at compile-time. The Callback article has more information about delegation.

The authors also discuss so-called parameterized types, which are also known as generics (Ada, Eiffel, Java, C#, Visual Basic (.NET), and Delphi) or templates (C++). These allow any type to be defined without specifying all the other types it uses—the unspecified types are supplied as 'parameters' at the point of use.

The authors admit that delegation and parameterization are very powerful but add a warning:

"Dynamic, highly parameterized software is harder to understand and build than more static software." (Gang of Four 1995:21)

The authors further distinguish between 'Aggregation', where one object 'has' or 'is part of' another object (implying that an aggregate object and its owner have identical lifetimes) and acquaintance, where one object merely 'knows of' another object. Sometimes acquaintance is called 'association' or the 'using' relationship. Acquaintance objects may request operations of each other, but they are not responsible for each other. Acquaintance is a weaker relationship than aggregation and suggests much looser coupling between objects, which can often be desirable for maximum maintainability in designs.

The authors employ the term 'toolkit' where others might today use 'class library', as in C# or Java. In their parlance, toolkits are the object-oriented equivalent of subroutine libraries, whereas a 'framework' is a set of cooperating classes that make up a reusable design for a specific class of software. They state that applications are hard to design, toolkits are harder, and frameworks are the hardest to design.

Patterns by type

edit

Creational

edit
  1. ↑ Hunt, John (26 January 2013). Hunt, John (ed.). Scala Design Patterns: Patterns for Practical Reuse and Design. Springer International Publishing. pp. 135–136. doi:10.1007/978-3-319-02192-8_16 – via Springer Link.
  2. ↑ "SIGPLAN FY '05 Annual Report" (PDF).{{cite web}}: CS1 maint: url-status (link)
  3. ↑ Hannemann, Jan; Kiczales, Gregor (4 November 2002). "Design pattern implementation in Java and aspectJ". ACM SIGPLAN Notices. 37 (11): 161–173. doi:10.1145/583854.582436. Archived from the original on 9 March 2025 – via ACM Digital Library.
  4. ↑

View original on Wikipedia | Back | FazBrowse Home