Content deleted Content added
→Criticism: Bring Paul Graham quote references together. |
Citation bot (talk | contribs) Added bibcode. Removed URL that duplicated identifier. | Use this bot. Report bugs. | Suggested by Headbomb | Linked from Wikipedia:WikiProject_Academic_Journals/Journals_cited_by_Wikipedia/Sandbox | #UCB_webform_linked 646/1032 |
||
(59 intermediate revisions by 44 users not shown) | |||
Line 1:
{{Short description|1994 software engineering book}}
{{hatnote|This article is about the book. For the generic articles, see [[software design pattern]] and [[design pattern]].}}
{{cleanup reorganize|date=July 2013}}
{{Use dmy dates|date=January 2024}}
{{Use American English|date=January 2024}}
{{Infobox book
| name
| image
| author
| illustrator
| cover_artist
| country
| subject
| genre
| publisher
| pub_date
| media_type
| pages
| isbn
| oclc
| dewey
| congress
}}
'''''Design Patterns: Elements of Reusable Object-Oriented Software''''' (1994) is a [[software engineering]] book describing [[software design pattern]]s. The book was written by [[Erich Gamma]], [[Richard Helm]], [[Ralph Johnson (computer scientist)|Ralph Johnson]], and [[John Vlissides]], with a foreword by [[Grady Booch]].
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.<ref name="copies-sold">{{cite book|url=https://doi.org/10.1007/978-1-4302-2821-9_13|title=Pro ODP .NET for Oracle Database 11g|first=Edmund|last=Zehoo|editor-first=Edmund|editor-last=Zehoo|date=26 January 2010|publisher=Apress|pages=351–371|via=Springer Link|doi=10.1007/978-1-4302-2821-9_13}}</ref> The authors are often referred to as the ''Gang of Four'' (GoF).<ref name="gof1">{{cite book|title=2017 IEEE International Conference on Software Quality, Reliability and Security (QRS)|doi=10.1109/QRS.2017.37 |s2cid=21343926 |chapter=The Effect of Gang-of-Four Design Patterns Usage on Design Quality Attributes |date=2017 |last1=Hussain |first1=Shahid |last2=Keung |first2=Jacky |last3=Khan |first3=Arif Ali |pages=263–273 |isbn=978-1-5386-0592-9 }}</ref><ref name="gof2">{{cite book|url=https://doi.org/10.1007/978-3-319-02192-8_16|title=Scala Design Patterns: Patterns for Practical Reuse and Design|first=John|last=Hunt|editor-first=John|editor-last=Hunt|date=26 January 2013|publisher=Springer International Publishing|pages=135–136|via=Springer Link|doi=10.1007/978-3-319-02192-8_16}}</ref><ref name="gof3">{{cite journal|title=Bad Smells of Gang of Four Design Patterns: A Decade Systematic Literature Review|first1=Sara H. S.|last1=Almadi|first2=Danial|last2=Hooshyar|first3=Rodina Binti|last3=Ahmad|date=26 January 2021|journal=Sustainability|volume=13|issue=18|pages=10256|doi=10.3390/su131810256|bibcode=2021Sust...1310256A |doi-access=free }}</ref><ref name="gof4">{{cite book|url=https://repositorium.sdum.uminho.pt/handle/1822/752|title=Pitfalls of aspectJ implementations of some of the gang-of-four design patterns|first1=Miguel Pessoa|last1=Monteiro|first2=João M.|last2=Fernandes|date=26 January 2004|publisher=Universidad de Extremadura|isbn=978-84-688-8889-7 |via=repositorium.uminho.pt}}</ref>
==Development and publication history==
The book started at a
==Introduction==
{{Overly detailed|section|date=October 2020}}
Chapter 1 is a discussion of [[Object-oriented programming|object-oriented]] design techniques, based on the authors' experience, which they believe would lead to good object-oriented software design, including:
* "Program to an interface, not an implementation." (Gang of Four 1995:18)
*
The authors claim the following as advantages of [[Interface (computer science)|interfaces]] over implementation:
* clients remain unaware of the specific types of objects they use, as long as the object adheres to the interface
* clients remain unaware of the classes that implement these objects; clients only know about the abstract class(es) defining the interface
Use of an interface also leads to [[Dynamic dispatch|dynamic binding]] and [[Polymorphism
The authors refer to [[Inheritance (object-oriented programming)|inheritance]] as ''[[White box (software engineering)|white-box]] reuse'', with white-box referring to visibility, because the internals of parent classes are often visible to [[Subclass (computer science)|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|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).
:"Because inheritance exposes a [[Subclass (computer science)|subclass]] to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'". (Gang of Four 1995:19)
Line 54 ⟶ 52:
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.
The authors also discuss so-called
The authors admit that delegation and parameterization are very powerful but add a warning:
Line 62 ⟶ 60:
:"Dynamic, highly parameterized software is harder to understand and build than more static software." (Gang of Four 1995:21)
The authors further distinguish between '[[Object composition#Aggregation|Aggregation]]', where one object 'has' or 'is part of' another object (implying that an aggregate object and its owner have identical lifetimes) and
The authors employ the term 'toolkit' where others might today use 'class library', as in C# or Java.
== Patterns by type ==
Line 221 ⟶ 69:
{{main|Creational pattern}}
[[Creational pattern]]s are ones that create objects, rather than having to instantiate objects directly. This gives the program more flexibility in deciding which objects need to be created for a given case.
* [[Abstract factory pattern|Abstract factory]] groups object factories that have a common theme.
* [[Builder pattern|Builder]] constructs complex objects by separating construction and representation.
Line 229 ⟶ 76:
===Structural===
* [[Adapter pattern|Adapter]] allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.
* [[Bridge pattern|Bridge]] decouples an abstraction from its implementation so that the two can vary independently.
* [[Composite pattern|Composite]] composes zero-or-more similar objects so that they can be manipulated as one object.
* [[Decorator pattern|Decorator]] dynamically adds/overrides
* [[Facade pattern|Facade]] provides a simplified interface to a large body of code.
* [[Flyweight pattern|Flyweight]] reduces the cost of creating and manipulating a large number of similar objects.
Line 239 ⟶ 86:
===Behavioral===
Most
* [[Chain-of-responsibility pattern|Chain of responsibility]] delegates commands to a chain of processing objects.
* [[Command pattern|Command]] creates objects
* [[Interpreter pattern|Interpreter]] implements a specialized language.
* [[Iterator pattern|Iterator]] accesses the elements of an object sequentially without exposing its underlying representation.
* [[Mediator pattern|Mediator]] allows [[loose coupling]] between classes by being the only class that has detailed knowledge of their methods.
* [[Memento pattern|Memento]] provides the ability to restore an object to its previous state (undo).
* [[Observer pattern|Observer]] is a publish/subscribe pattern, which allows a number of observer objects to see an event.
* [[State pattern|State]] allows an object to alter its behavior when its internal state changes.
* [[Strategy pattern|Strategy]] allows one of a family of algorithms to be selected on-the-fly at runtime.
Line 253 ⟶ 99:
* [[Visitor pattern|Visitor]] separates an algorithm from an object structure by moving the hierarchy of methods into one object.
==
In 2005 the ACM [[SIGPLAN]] awarded that year's Programming Languages Achievement Award to the authors, in recognition of the impact of their work "on programming practice and [[programming language]] design".<ref>{{cite web|url=http://www.sigplan.org/sites/default/files/report2005.pdf|title=SIGPLAN FY '05 Annual Report}}</ref>
Criticism has been directed at the concept of [[software design pattern]]s generally, and at ''Design Patterns'' specifically. A primary criticism of ''Design Patterns'' is that its patterns are simply workarounds for missing features in C++, replacing elegant abstract features with lengthy concrete patterns, essentially becoming a "human compiler". [[Paul Graham (programmer)|Paul Graham]] wrote:<ref name = "Graham2002">{{cite conference
| first1 = Paul
| author1-link = Paul Graham (computer programmer)
| title = Revenge of the Nerds
| url = http://www.paulgraham.com/icad.html
| access-date = 11 August 2012}}
</ref>
{{Quote|text=When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough-- often that I'm generating by hand the expansions of some macro that I need to write.}}
[[Peter Norvig]] demonstrates that 16 out of the 23 patterns in ''Design Patterns'' are simplified or eliminated
| title = Design Patterns in Dynamic Languages | year = 2002
| title = Design pattern implementation in Java and AspectJ
| url = http://hannemann.pbworks.com/w/page/16577895/Design%20Pattern
}}</ref>
In an interview with InformIT in 2009, Erich Gamma stated that the book authors had a discussion in 2005 on how they would have refactored the book and concluded that they would have recategorized some patterns and added a few additional ones, such as extension object/interface, dependency injection, type object, and null object. Gamma wanted to remove the singleton pattern, but there was no consensus among the authors to do so.<ref>{{cite interview |last1=Gamma |first1=Erich |last2=Helm |first2=Richard |last3=Johnson |first3=Ralph |interviewer=Larry O'Brien |date=22 October 2009 |title=Design Patterns 15 Years Later: An Interview with Erich Gamma, Richard Helm, and Ralph Johnson |url=http://www.informit.com/articles/article.aspx?p=1404056 |work=InformIT |access-date=1 September 2019 |archive-url=https://web.archive.org/web/20190220090254/http://www.informit.com/articles/article.aspx?p=1404056 |archive-date=20 February 2019 |url-status=live}}</ref>
==See also==
* [[Software design pattern]]
* [[Enterprise Integration Patterns]]
* [[GRASP (object-oriented design)]]
* [[Pedagogical
==References==
{{
{{Design
{{DEFAULTSORT:Design Patterns (Book)}}
|