Design pattern (computer science)
From Free net encyclopedia
In software engineering, a design pattern is a general repeatable solution to a commonly-occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code; it is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems.
Contents |
History
Patterns originated as an architectural concept by Christopher Alexander. In 1987, Kent Beck and Ward Cunningham began experimenting with the idea of applying patterns to programming and presented their results at the OOPSLA conference that year. In the following years, Beck, Cunningham and others followed up on this work.
Design patterns gained popularity in computer science after the book Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994 (Gamma et al). That same year, the first Pattern Languages of Programs conference was held and the following year, the Portland Pattern Repository was set up for documentation of design patterns. The scope of the term remained a matter of dispute into the next decade.
Uses
Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.
Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn't require specifics tied to a particular problem.
Design patterns are composed of several sections (see Documentation). Of particular interest are the Structure, Participants, and Collaboration sections. These sections describe a design motif: a prototypical micro-architecture that developers copy and adapt to their particular designs to solve the recurrent problem described by the design pattern. (A micro-architecture is a set of program constituents (e.g., classes, methods...) and their relationships.) Developers use the design pattern by introducing in their designs this prototypical micro-architecture, which means that micro-architectures in their designs will have structure and organization similar to the chosen design motif.
In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.
Classification
Design patterns can be classified based on multiple criteria, the most common of which is the basic underlying problem they solve. According to this criterion, design patterns can be classified into various classes, some of which are:
- Fundamental patterns
- Creational patterns
- Structural patterns
- Behavioral patterns
- Concurrency patterns
- Architectural patterns
Documentation
The documentation for a design pattern should contain enough information about the problem that the pattern addresses, the context in which it is used, and the suggested solution. Nonetheless, authors use their own layouts to document design patterns, and these layouts usually resemble the essential parts. The authors usually include additional sections to provide more information, and organize the essential parts in different sections, possibly with different names.
A commonly used format is the one used by the Gang of Four. It contains the following sections:
- Pattern Name and Classification: Every pattern should have a descriptive and unique name that helps in identifying and referring to it. Additionally, the pattern should be classified according to a classification such as the one described earlier. This classification helps in identifying the use of the pattern.
- Intent: This section should describe the goal behind the pattern and the reason for using it. It resembles the problem part of the pattern.
- Also Known As: A pattern could have more than one name. These names should be documented in this section.
- Motivation: This section provides a scenario consisting of a problem and a context in which this pattern can be used. By relating the problem and the context, this section shows when this pattern is used.
- Applicability: This section includes situations in which this pattern is usable. It represents the context part of the pattern.
- Structure: A graphical representation of the pattern. Class diagrams and Interaction diagrams can be used for this purpose.
- Participants: A listing of the classes and objects used in this pattern and their roles in the design.
- Collaboration: Describes how classes and objects used in the pattern interact with each other.
- Consequences: This section describes the results, side effects, and trade offs caused by using this pattern.
- Implementation: This section describes the implementation of the pattern, and represents the solution part of the pattern. It provides the techniques used in implementing this pattern, and suggests ways for this implementation.
- Sample Code: An illustration of how this pattern can be used in a programming language
- Known Uses: This section includes examples of real usages of this pattern.
- Related Patterns: This section includes other patterns that have some relation with this pattern, so that they can be used along with this pattern, or instead of this pattern. It also includes the differences this pattern has with similar patterns.
Critique
The concept of design patterns has been criticized by some in the field of computer science.
Design patterns and insufficient abstraction
Some feel that the need for patterns results from using computer languages or techniques with insufficient abstraction ability. Under ideal factoring, a concept should not be copied, but merely referenced. But if something is referenced instead of copied, then there is no "pattern" to label and catalog. Paul Graham writes in the essay Revenge of the Nerds.Template:Ref
This practice is not only common, but institutionalized. For example, in the OO world you hear a good deal about "patterns". I wonder if these patterns are not sometimes evidence of case (c), the human compiler, at work. 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 provides a similar argument - he demonstrates that 16 out of the 23 patterns in the Design Patterns book (which is primarily focused on C++) are simplified or eliminated (via direct language support) in Lisp or Dylan.Template:Ref
Further arguments along this line are discussed on WikiWikiWeb.Template:RefTemplate:Ref
Theoretical foundation of design patterns
Some theoreticians have suggested that the study of design patterns has been excessively ad hoc, and that the concept sorely needs to be put on a more formal footing. At OOPSLA 1999, the Gang of Four were (with their full cooperation) subjected to a show trial Template:Ref, in which they were "charged" with numerous crimes against computer science. (They were "convicted" by 2/3 of the "jurors" who attended the trial.) Template:Ref
See also
- Design Patterns for the list of patterns in the book by Gamma et al.
- Anti-pattern
- Pattern mining
- Pedagogical patterns
- Portland Pattern Repository
- Programming practice
- Refactoring
- Software engineering and List of software engineering topics
- Business Process Improvement Pattern
References
- {{cite book
| first = Christopher | last = Alexander | authorlink = Christopher Alexander | coauthors = et al | year = | title = A Pattern Language: Towns, Buildings, Construction | location= New York | publisher=Oxford University Press | id =
}}
- {{cite book
| first = K. | last = Beck | authorlink = | coauthors = R. Crocker, G. Meszaros, J.O. Coplien, L. Dominick, F. Paulisch, and J. Vlissides | year = 1996 | month = March | title = Proceedings of the 18th International Conference on Software Engineering | pages = 25-30 | publisher = | id =
}}
- {{cite web
| author = Beck, Kent, Ward Cunningham | url = http://c2.com/doc/oopsla87.html | accessdate = 2006-01-20 | title = Using Pattern Languages for Object-Oriented Programs | publisher = The Workshop on the Specification and Design for Object-Oriented Programming at OOPSLA '87 | year = 1987
}}
- {{cite book
| first = Jan | last = Borchers | authorlink = Jan Borchers | year = 2001 | title = A Pattern Approach to Interaction Design | publisher = John Wiley & Sons | id = ISBN 0-471-49828-9
}}
- {{cite book
| first = Frank | last = Buschmann | authorlink = Frank Buschmann | coauthors = Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal | year = | title = Pattern-oriented Software Architecture, Volume 1: A System of Patterns | publisher = John Wiley & Sons | id = ISBN 0471958697
}}
- {{cite book
| first = James W. | last = Cooper | authorlink = | year = 1998 | month = October | title = The Design Patterns Java Companion | publisher = Addison-Wesley | id =
}}
- {{cite book
| first = James O. | last = Coplien | authorlink = James O. Coplien | coauthors = Douglas C. Schmidt | year = | title = Pattern Languages of Program Design | publisher = Addison-Wesley | id = ISBN 0201607344
}}
- {{cite book
| first = James O. | last = Coplien | authorlink = | coauthors = John M. Vlissides, and Norman L. Kerth | year = | title = Pattern Languages of Program Design 2 | publisher = Addison-Wesley | id = ISBN 0201895277
}}
- {{cite book
| first = Ward | last = Cunningham | authorlink = Ward Cunningham | coauthors = Kent Beck | date = May 16, 1988 | title = Addendum to the Proceedings of OOPSLA'87, volume 23,5 of ACM SIGPLAN Notices | chapter = Using a pattern language for programming | pages = | publisher = | id =
}}
- {{cite book
| first = Mathijs | last = den Burger | authorlink = | year = 2002 | month = March | title = Design Patterns for Networking Applications in Java | publisher = | id =
}}
- {{cite book
| first = Martin | last = Fowler | authorlink = Martin Fowler | year = | title = Patterns of Enterprise Application Architecture | publisher = Addison-Wesley | id = ISBN 0321127420
}}
- Fowler, Martin. Patterns [software patterns] Software, IEEE, Volume: 20, Issue: 2, March-April 2003. Pages: 56 – 57.
- {{cite book
| first = Eric | last = Freeman | authorlink = Eric Freeman | coauthors = Elisabeth Freeman, Kathy Sierra, and Bert Bates | title = Head First Design Patterns | year = 2004 | publisher = O'Reilly Media | pages = 637 | id = ISBN 0-596-00712-4
}}
- {{cite book
| first = Erich | last = Gamma | authorlink = Erich Gamma | coauthors = Richard Helm, Ralph Johnson, and John Vlissides | year = 1995 | title = Design Patterns: Elements of Reusable Object-Oriented Software | others = hardcover, 395 pages | publisher = Addison-Wesley | id = ISBN 0201633612
}}
- {{cite book
| first = Erich | last = Gamma | authorlink = Erich Gamma | coauthors = Richard Helm, Ralph Johnson, and John Vlissides | year = 1997 | title = Design Patterns CD | id = ISBN 0201634988
}}
- {{cite book
| first = Neil | last = Harrison | authorlink = Neil Harrison | coauthors = Brian Foote, and Hans Rohnert | year = | title = Pattern Languages of Program Design 4 | publisher = Addison-Wesley | id = ISBN 0201433044
}}
- {{cite book
| first = Gregor | last = Hohpe | authorlink = Gregor Hohpe | coauthors = Bobby Woolf | year = 2004 | title = Enterprise Integration Patterns | publisher = Addison-Wesley | id = ISBN 0321200683
}}
- {{cite book
| first = Allen | last = Holub | authorlink = Allen Holub | coauthors = | year = 2004 | title = Holub on Patterns | publisher = Apress Publishers | id = ISBN 159059388X
}}
- {{cite book
| first = Jonathan | last = Kaplan | authorlink = Jonathan Kaplan | coauthors = William C. R. Crawford | year = | title = J2EE Design Patterns | publisher = O'Reilly | id = ISBN 0-596-00427-3
}}
- {{cite book
| first = Joshua | last = Kerievsky | authorlink = | coauthors = | year = 2004 | title = Refactoring to Patterns | publisher = Addison-Wesley | id = ISBN 0-321-21335-1
}}
- {{cite book
| first = Michael | last = Kircher | authorlink = Michael Kircher | coauthors = Prashant Jain | year = | title = Pattern-oriented Software Architecture. Volume 3: Patterns for Resource Management | publisher = John Wiley & Sons | id = ISBN 0470845252
}}
- {{cite book
| first = Michael | last = Kircher | authorlink = Michael Kircher | coauthors = Markus Völter and Uwe Zdun | year = 2005 | title = Remoting Patterns: Foundations of Enterprise, Internet and Realtime Distributed Object Middleware | publisher = John Wiley & Sons | id = ISBN 0470856629
}}
- {{cite book
| first = Floyd | last = Marinescu | authorlink = Floyd Marinescu | year = | title = EJB Design Patterns: Advanced Patterns, Processes and Idioms | publisher = John Wiley & Sons | id = ISBN 0-471-20831-0
}}
- {{cite book
| first = Robert Cecil | last = Martin | authorlink = Robert Cecil Martin | coauthors = Dirk Riehle, and Frank Buschmann | title = Pattern Languages of Program Design 3 | publisher = Addison-Wesley | id = ISBN 0201310112
}}
- {{cite book
| first = Clifton | last = Nock | authorlink = Clifton Nock | year = 2003 | title = Data Access Patterns: Database Interactions in Object-Oriented Applications | publisher = Addison-Wesley | id = ISBN 0-13-140157-2
}}
- {{cite book
| first = Douglas C. | last = Schmidt | authorlink = Douglas C. Schmidt | coauthors = Michael Stal, Hans Rohnert, and Frank Buschmann | year = | title = Pattern-oriented Software Architecture. Volume 2: Patterns for Concurrent and Networked Objects | publisher = John Wiley & Sons | id = ISBN 0471606952
}}
- {{cite book
| first = Douglas C. | last = Schmidt | authorlink = Douglas C. Schmidt | coauthors = Stephen D. Huston | year = | title = C++ Network Programming: Mastering Complexity Using ACE and Patterns | publisher = Addison-Wesley | id = ISBN 0201604647
}}
- {{cite book
| first = Alan | last = Shalloway | authorlink = Alan Shalloway | coauthors = James R. Trott | year = | title = Design Patterns Explained: A New Perspective on Object-Oriented Design | publisher = Addison-Wesley | id = ISBN 0201715945
}}
- {{cite book
| first = John M. | last = Vlissides | authorlink = John M. Vlissides | year = | title = Pattern Hatching: Design Patterns Applied | publisher = Addison-Wesley | id = ISBN 0-201-43293-5
}}
- {{cite web
| url = http://c2.com/cgi-bin/wiki?HistoryOfPatterns | title = History of Patterns | work = Portland Pattern Repository | accessdate = 2005-07-28
}}
- Template:Note {{cite web
| url = http://www.paulgraham.com/icad.html | accessdate = 2006-01-20 | title = Revenge of the Nerds | author = Paul Graham | year = May 2002
}}
- Template:Note {{cite web
| url = http://norvig.com/design-patterns/ | accessdate = 2006-01-20 | title = Design Patterns in Dynamic Programming | author = Peter Norvig | year = 1998-03-17
}}
- Template:Note {{cite web
| url = http://www.c2.com/cgi/wiki?AreDesignPatternsMissingLanguageFeatures | accessdate = 2006-01-20 | title = Are Design Patterns Missing Language Features? | publisher = Cunningham & Cunningham, Inc.
}}
- Template:Note {{cite web
| url = http://www.c2.com/cgi/wiki?DesignPatternsInDynamicProgramming | accessdate = 2006-01-20 |title = Design Patterns in Dynamic Programming | publisher = Cunningham & Cunningham, Inc.
}}
- Template:Note {{cite web
| url = http://www.c2.com/cgi/wiki?ShowTrialOfTheGangOfFour | accessdate = 2006-01-20 | title = Show Trial of the Gang of Four | publisher = Cunningham & Cunningham, Inc.
}}
- Template:Note {{cite web
| url = http://www.c2.com/cgi/wiki?ShowTrialVerdict | accessdate = 2006-01-20 | title = Show Trial Verdict | publisher = Cunningham & Cunningham, Inc.
}}
External links
- Design Patterns in C# and VB.NET
- AJAX Design Patterns
- Design Patterns for PHP
- Java J2EE pattern catalog
- Design Patterns in Java
- Microsoft patterns & practices catalog
- Patterns Catalog
- Design Pattern Toolkit
- XML structural design patterns.
- Perl Design Patterns
- The PatternShare community - community site for sharing patterns.
- TechBookReport - reviews of books on design
- Many design patterns are described in mgrand's bookpatterns and software methodologies
- The list of design patterns is entirely based on a wiki page http://c2.com/cgi/wiki?CategoryPattern.
- Formal and precise software pattern representation languages
- LePUS--Language for Patterns Uniform Specification
- Formalisation, detection, and enhancement of object-oriented programs using patterns
- Perl Design Patterns TinyWiki
- Yahoo! Design Pattern Library
- Huston Design Patternsast:Patrón de diseñu
bs:Dizajn Šema (računari) cs:Návrhový vzor de:Entwurfsmuster es:Patrón de diseño fr:Motif de conception it:Design pattern he:Design pattern (מדעי המחשב) lt:Projektavimo pavyzdys nl:Ontwerppatroon ja:デザインパターン no:Design pattern pl:Wzorzec projektowy pt:Padrões de projeto de software ru:Шаблоны проектирования fi:Suunnittelumalli sv:Designmönster vi:Mẫu thiết kế (khoa học máy tính) tr:Tasarım kalıpları zh:软件设计模式