Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Software design pattern
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Reusable solution to a commonly occurring software problem}} In [[software engineering]], a '''software design pattern''' or '''design pattern''' is a general, [[reusability|reusable]] solution to a commonly occurring problem in many contexts in [[software design]].<ref>{{cite book |last=Alexandrescu |first=Andrei |date=2001 |title=Modern C++ Design: Generic Programming and Design Patterns Applied |publisher=Addison-Wesley |page=xviii |isbn=978-0-201-70431-0}}</ref> A design pattern is not a rigid structure to be transplanted directly into [[source code]]. Rather, it is a description or a template for solving a particular type of problem that can be deployed in many different situations.<ref>{{cite book |last=Horner |first=Mark |date=2005 |title=Pro .NET 2.0 Code and Design Standards in C# |publisher=Apress |chapter=9 |page=171|isbn=978-1-59059-560-2 }}</ref> Design patterns can be viewed as formalized [[best practice]]s that the programmer may use to solve common problems when designing a software application or system. [[Object-oriented]] design patterns typically show relationships and interactions between [[class (computer science)|class]]es or [[object (computer science)|object]]s, without specifying the final application classes or objects that are involved.{{Citation needed|date=January 2025}} Patterns that imply mutable state may be unsuited for [[functional programming]] languages. Some patterns can be rendered unnecessary in languages that have built-in support for solving the problem they are trying to solve, and object-oriented patterns are not necessarily suitable for non-object-oriented languages.{{Citation needed|date=January 2025}} Design patterns may be viewed as a structured approach to [[computer programming]] intermediate between the levels of a [[programming paradigm]] and a concrete [[algorithm]].{{Citation needed|date=January 2025}} ==History== Patterns originated as an [[Pattern (architecture)|architectural concept]] by [[Christopher Alexander]] as early as 1977 in [[A Pattern Language]] (cf. his article, "The Pattern of Streets," JOURNAL OF THE AIP, September, 1966, Vol. 32, No. 5, pp. 273–278). In 1987, [[Kent Beck]] and [[Ward Cunningham]] began experimenting with the idea of applying patterns to programming – specifically [[pattern language]]s – and presented their results at the [[OOPSLA]] conference that year.<ref name = "Smith1987">{{cite conference | last = Smith | first = Reid | title = Panel on design methodology | conference = [[OOPSLA]] '87 Addendum to the Proceedings | doi = 10.1145/62138.62151 |date=October 1987 | quote=Ward cautioned against requiring too much programming at, what he termed, 'the high level of wizards.' He pointed out that a written 'pattern language' can significantly improve the selection and application of abstractions. He proposed a 'radical shift in the burden of design and implementation' basing the new methodology on an adaptation of Christopher Alexander's work in pattern languages and that programming-oriented pattern languages developed at [[Tektronix]] has significantly aided their software development efforts.}}</ref><ref name = "Beck1987">{{cite conference | last1 = Beck | first1 = Kent | author-link = Kent Beck | author-link2 = Ward Cunningham | first2 = Ward | last2 = Cunningham | title = Using Pattern Languages for Object-Oriented Program | conference = [[OOPSLA]] '87 workshop on ''Specification and Design for Object-Oriented Programming'' | url = http://c2.com/doc/oopsla87.html |date=September 1987 | access-date = 2006-05-26}}</ref> 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|''Design Patterns: Elements of Reusable Object-Oriented Software'']] was published in 1994 <!-- 1994, not 1995. See talk page. --> by the so-called "Gang of Four" (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides), which is frequently abbreviated as "GoF". That same year, the first [[Pattern Languages of Programming]] Conference was held, and the following year the [[Portland Pattern Repository]] was set up for documentation of design patterns. The scope of the term remains a matter of dispute. Notable books in the design pattern genre include: * {{cite book | first1 = Erich | last1 = Gamma | author-link = Erich Gamma | author-link2 = Richard Helm | first2 = Richard | last2 = Helm | author-link3 = Ralph Johnson (computer scientist) | first3 = Ralph | last3 = Johnson | author-link4 = John Vlissides | first4 = John | last4 = Vlissides | year = 1994 | title = Design Patterns: Elements of Reusable Object-Oriented Software | publisher = [[Addison-Wesley]] | isbn = 978-0-201-63361-0 | title-link = Design Patterns (book) }} * {{cite book | first = Per | last = Brinch Hansen | author-link = Per Brinch Hansen | date = 1995 | title = Studies in Computational Science: Parallel Programming Paradigms | publisher = Prentice Hall | isbn = 978-0-13-439324-7 }} * {{cite book | first1 = Frank | last1 = Buschmann | author-link = Frank Buschmann | first2 = Regine | last2 = Meunier | first3 = Hans | last3 = Rohnert | first4 = Peter | last4 = Sommerlad | date = 1996 | title = Pattern-Oriented Software Architecture, Volume 1: A System of Patterns | publisher = John Wiley & Sons | isbn = 978-0-471-95869-7 }} * {{cite book | first = Kent | last = Beck | author-link = Kent Beck | year = 1997 | title = Smalltalk Best Practice Patterns | publisher = Prentice Hall | isbn = 978-0134769042 }} * {{cite book | first1 = Douglas C. | last1 = Schmidt | author-link = Douglas C. Schmidt | first2=Michael | last2 = Stal | first3 = Hans | last3 = Rohnert | first4 = Frank | last4 = Buschmann | date = 2000 | title = Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects | publisher = John Wiley & Sons | isbn = 978-0-471-60695-6 }} * {{cite book | title = Patterns of Enterprise Application Architecture | first = Martin | last = Fowler | author-link = Martin Fowler (software engineer) | year = 2002 | isbn = 978-0-321-12742-6 | publisher = [[Addison-Wesley]] }} * {{cite book | first1 = Gregor | last1 = Hohpe | first2 = Bobby | last2 = Woolf | date = 2003 | title = Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions | publisher = [[Addison-Wesley]] | isbn = 978-0-321-20068-6 | title-link = Enterprise Integration Patterns }} * {{cite book | first1 = Eric T. | last1 = Freeman | first2 = Elisabeth | last2 = Robson | first3 = Bert | last3 = Bates | first4 = Kathy | last4 = Sierra | author-link4 = Kathy Sierra | date = 2004 | title = Head First Design Patterns | publisher = [[O'Reilly Media]] | isbn = 978-0-596-00712-6 }} * {{cite book | first = Craig | last = Larman | author-link = Craig Larman | year = 2004 | title = Applying UML and Patterns (3rd Ed, 1st Ed 1995) | publisher = Pearson | isbn = 978-0131489066 }} Although design patterns have been applied practically for a long time, formalization of the concept of design patterns languished for several years.<ref name = "Baroni2003">{{cite report | s2cid = 624834 | citeseerx = 10.1.1.62.6466 | title = Design Patterns Formalization | first1 = Aline Lúcia | last1 = Baroni | first2 = Yann-Gaël | last2 = Guéhéneuc | first3 = Hervé | last3 = Albin-Amiot | date=June 2003 | publisher = École Nationale Supérieure des Techniques Industrielles et des Mines de Nantes | location = [[Nantes]] | series = EMN Technical Report |url=https://www.researchgate.net/publication/277282980 | via = ResearchGate }}</ref> == Practice == Design patterns can speed up the development process by providing proven development paradigms.<ref>{{cite web | url = http://msdn.microsoft.com/en-us/vstudio/ff729657 | first = Judith | last = Bishop | title = C# 3.0 Design Patterns: Use the Power of C# 3.0 to Solve Real-World Problems | publisher = C# Books from O'Reilly Media | quote = If you want to speed up the development of your .NET applications, you're ready for C# design patterns -- elegant, accepted and proven ways to tackle common programming problems. | access-date = 2012-05-15 }}</ref> Effective software design requires considering issues that may not become apparent until later in the implementation. Freshly written code can often have hidden, subtle issues that take time to be detected; issues that sometimes can cause major problems down the road. Reusing design patterns can help to prevent such issues,<ref>{{cite book |chapter-url=https://books.google.com/books?id=_SklFgSidxQC&q=Reusing+design+patterns+helps+to+prevent+such+subtle+issues&pg=PA636 |page=636|title=Software Applications: Concepts, Methodologies, Tools, and Applications: Concepts, Methodologies, Tools, and Applications|isbn=9781605660615|last1=Tiako|first1=Pierre F.|editor-first1=Pierre F |editor-last1=Tiako |date=31 March 2009 |chapter=Formal Modeling and Specification of Design Patterns Using RTPA |doi=10.4018/978-1-60566-060-8}}</ref> and enhance code readability for those familiar with the patterns. Software design techniques are difficult to apply to a broader range of problems.{{Citation needed|date=August 2014}} Design patterns provide general solutions, [[documentation|documented]] in a format that does not require specifics tied to a particular problem. In 1996, Christopher Alexander was invited to give a [https://www.patternlanguage.com/archive/ieee.html Keynote Speech] to the 1996 OOPSLA Convention. Here he reflected on how his work on Patterns in Architecture had developed and his hopes for how the Software Design community could help Architecture extend Patterns to create living structures that use generative schemes that are more like computer code. ==Motif== A pattern describes a ''design motif'', a.k.a. ''prototypical micro-architecture'', as a set of program constituents (e.g., classes, methods...) and their relationships. A developer adapts the motif to their codebase to solve the problem described by the pattern. The resulting code has structure and organization similar to the chosen motif. ==Domain-specific patterns== Efforts have also been made to codify design patterns in particular domains, including the use of existing design patterns as well as domain-specific design patterns. Examples include [[user interface]] design patterns,<ref>{{cite web |last=Laakso |first=Sari A. |date=2003-09-16 |title=Collection of User Interface Design Patterns |url=http://www.cs.helsinki.fi/u/salaakso/patterns/index.html |access-date=2008-01-31 |publisher=University of Helsinki, Dept. of Computer Science}}</ref> [[information visualization]],<ref>{{cite journal | volume = 12 | issue = 5 | last1 = Heer | first1 = J. | first2 = M. | last2 = Agrawala | title = Software Design Patterns for Information Visualization | journal = IEEE Transactions on Visualization and Computer Graphics | date = 2006 | url = http://vis.berkeley.edu/papers/infovis_design_patterns/ | doi = 10.1109/TVCG.2006.178 | pmid = 17080809 | pages = 853–60 | citeseerx = 10.1.1.121.4534 | s2cid = 11634997 }}</ref> secure design,<ref>{{cite book | title= Secure Design Patterns | date = 2009 | first1 = Chad | last1 = Dougherty | first2 = Kirk | last2 = Sayre | first3 = Robert C. | last3 = Seacord | first4 = David | last4 = Svoboda | first5 = Kazuya | last5 = Togashi | url = http://www.cert.org/archive/pdf/09tr010.pdf | publisher = Software Engineering Institute }} </ref> "secure usability",<ref>{{cite thesis|type=Ph.D. thesis | title= Design Principles and Patterns for Computer Systems That Are Simultaneously Secure and Usable | date = 2005 | first = Simson L. | last = Garfinkel | url = http://www.simson.net/thesis/ }}</ref> Web design <ref>{{cite web |title = Yahoo! Design Pattern Library |access-date = 2008-01-31 |url = http://developer.yahoo.com/ypatterns/ |url-status = dead |archive-url = https://web.archive.org/web/20080229011119/http://developer.yahoo.com/ypatterns/ |archive-date = 2008-02-29 }}</ref> and business model design.<ref>{{cite web | title = How to design your Business Model as a Lean Startup? | access-date = 2010-01-06 | url = http://torgronsund.wordpress.com/2010/01/06/lean-startup-business-model-pattern/ | date = 2010-01-06 }}</ref> The annual [[Pattern Languages of Programming]] Conference proceedings <ref>Pattern Languages of Programming, Conference proceedings (annual, 1994—) [http://hillside.net/plop/pastconferences.html]</ref> include many examples of domain-specific patterns. == Object-oriented programming == [[Object-oriented]] design patterns typically show relationships and interactions between [[class (computer science)|class]]es or [[object (computer science)|object]]s, without specifying the final application classes or objects that are involved. Patterns that imply mutable state may be unsuited for [[functional programming]] languages. Some patterns can be rendered unnecessary in languages that have built-in support for solving the problem they are trying to solve, and object-oriented patterns are not necessarily suitable for non-object-oriented languages. ==Examples== Design patterns can be organized into groups based on what kind of problem they solve. [[Creational pattern]]s create objects. [[Structural pattern]]s organize classes and objects to form larger structures that provide new functionality. [[Behavioral pattern]]s describe collaboration between objects. === [[Creational patterns]] === {| class="wikitable" |- ! Name ! Description ! In ''[[Design Patterns]]'' ! In ''[[Code Complete]]''<ref name="McConnell2004">{{cite book | title = Code Complete | first = Steve | last = McConnell | author-link = Steve McConnell |date=June 2004 | publisher = [[Microsoft Press]] | isbn = 978-0-7356-1967-8 | chapter = Design in Construction | quote = Table 5.1 Popular Design Patterns | edition = 2nd | page = [https://archive.org/details/codecomplete0000mcco/page/104 104] | title-link = Code Complete }}</ref> ! Other |- | [[Abstract factory]] | Provide an interface for creating ''families'' of related or dependent objects without specifying their concrete classes. | {{yes}} | {{yes}} | {{n/a}} |- | [[Builder pattern|Builder]] | Separate the construction of a complex object from its representation, allowing the same construction process to create various representations. | {{yes}} | {{yes}} | {{n/a}} |- | [[Dependency Injection]] | A class accepts the objects it requires from an injector instead of creating the objects directly. | {{n/a}} | {{yes}} | {{n/a}} |- | [[Factory method]] | Define an interface for creating a ''single'' object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. | {{yes}} | {{yes}} | {{n/a}} |- | [[Lazy initialization]] | Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed. This pattern appears in the GoF catalog as "virtual proxy", an implementation strategy for the [[Proxy pattern|Proxy]] pattern. | {{yes}} | {{yes}} | {{yes|{{abbr|PoEAA|Patterns of Enterprise Application Architecture}}<ref name = "PoEAA"> {{cite book | first = Martin | last = Fowler | author-link = Martin Fowler (software engineer) | year = 2002 | title = Patterns of Enterprise Application Architecture | publisher = [[Addison-Wesley]] | isbn = 978-0-321-12742-6 | url = http://martinfowler.com/books.html#eaa }}</ref>}} |- | [[Multiton]] | Ensure a class has only named instances, and provide a global point of access to them. | {{yes}} | {{yes}} | {{yes}} |- | [[Object pool]] | Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. Can be considered a generalisation of [[connection pool]] and [[thread pool]] patterns. | {{yes}} | {{yes}} | {{yes}} |- | [[Prototype pattern|Prototype]] | Specify the kinds of objects to create using a prototypical instance, and create new objects from the 'skeleton' of an existing object, thus boosting performance and keeping memory footprints to a minimum. | {{yes}} | {{yes}} | {{yes}} |- | [[Resource acquisition is initialization]] (RAII) | Ensure that resources are properly released by tying them to the lifespan of suitable objects. | {{yes}} | {{yes}} | {{yes}} |- | [[Singleton pattern|Singleton]] | Ensure a class has only one instance, and provide a global point of access to it. | {{yes}} | {{yes}} | {{yes}} |} === [[Structural pattern]]s === {| class="wikitable" |- ! Name ! Description ! In ''[[Design Patterns]]'' ! In ''[[Code Complete]]''<ref name="McConnell2004" /> ! Other |- | [[Adapter pattern|Adapter]], Wrapper, or Translator | Convert the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces. The enterprise integration pattern equivalent is the translator. | {{yes}} | {{yes}} | {{yes}} |- | [[Bridge pattern|Bridge]] | Decouple an abstraction from its implementation allowing the two to vary independently. | {{yes}} | {{yes}} | {{yes}} |- | [[Composite pattern|Composite]] | Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. | {{yes}} | {{yes}} | {{yes}} |- | [[Decorator pattern|Decorator]] | Attach additional responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible alternative to subclassing for extending functionality. | {{yes}} | {{yes}} | {{yes}} |- | [[Delegation pattern|Delegation]] | Extend a class by composition instead of subclassing. The object handles a request by delegating to a second object (the delegate) | {{yes}} | {{yes}} | {{yes}} |- | Extension object | Adding functionality to a hierarchy without changing the hierarchy. | {{yes}} | {{yes}} | {{yes}} |- | [[Facade pattern|Facade]] | Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. | {{yes}} | {{yes}} | {{yes}} |- | [[Flyweight pattern|Flyweight]] | Use sharing to support large numbers of similar objects efficiently. | {{yes}} | {{yes}} | {{yes}} |- | [[Front controller]] | The pattern relates to the design of Web applications. It provides a centralized entry point for handling requests. | {{yes}} | {{yes}} | {{yes| {{abbr|J2EE Patterns|Core J2EE Patterns: Best Practices and Design Strategies (2nd Edition)}}<ref name = "J2EE Patterns"> {{cite book | first1 = Deepak | last1 = Alur | first2 = John | last2 = Crupi | first3 = Dan | last3 = Malks | year = 2003 | title = Core J2EE Patterns: Best Practices and Design Strategies | page = 166 | publisher = [[Prentice Hall]] | isbn = 978-0-13-142246-9 | url = http://www.corej2eepatterns.com }}</ref> {{abbr|PoEAA|Patterns of Enterprise Application Architecture}}<ref name = "PoEAA2"> {{cite book | first = Martin | last = Fowler | author-link = Martin Fowler (software engineer) | year = 2002 | title = Patterns of Enterprise Application Architecture | page = 344 | publisher = [[Addison-Wesley]] | isbn = 978-0-321-12742-6 | url = http://martinfowler.com/books.html#eaa }}</ref>}} |- | [[Marker interface pattern|Marker]] | Empty interface to associate metadata with a class. | {{yes}} | {{yes}} | {{yes|[[Joshua Bloch|Effective Java]]<ref name="EffectiveJava"> {{cite book | last = Bloch | first = Joshua | title = Effective Java | page = [https://archive.org/details/effectivejava00bloc_0/page/179 179] | chapter = Item 37: Use marker interfaces to define types | year = 2008 | isbn = 978-0-321-35668-0 | publisher = Addison-Wesley | chapter-url = https://archive.org/details/effectivejava00bloc_0/page/179 | edition = Second }}</ref>}} |- | [[Module pattern|Module]] | Group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity. | {{yes}} | {{yes}} | {{yes}} |- | [[Proxy pattern|Proxy]] | Provide a surrogate or placeholder for another object to control access to it. | {{yes}} | {{yes}} | {{yes}} |- | [[Twin pattern|Twin]]<ref>{{cite web|url=http://www.ssw.jku.at/Research/Papers/Moe99/Paper.pdf |title=Twin – A Design Pattern for Modeling Multiple Inheritance }}</ref> | Twin allows modeling of multiple inheritance in programming languages that do not support this feature. | {{yes}} | {{yes}} | {{yes}} |} === [[Behavioral patterns]] === {| class="wikitable" |- ! Name ! Description ! In ''[[Design Patterns]]'' ! In ''[[Code Complete]]''<ref name="McConnell2004" /> ! Other |- | [[Blackboard (design pattern)|Blackboard]] | [[Artificial intelligence]] pattern for combining disparate sources of data (see [[blackboard system]]) | {{yes}} | {{yes}} | {{yes}} |- | [[Chain-of-responsibility pattern|Chain of responsibility]] | Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. | {{yes}} | {{yes}} | {{yes}} |- | [[Command pattern|Command]] | Encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests, and the queuing or logging of requests. It also allows for the support of undoable operations. | {{yes}} | {{yes}} | {{yes}} |- |[[Fluent interface]] | Design an API to be method chained so that it reads like a DSL. Each method call returns a context through which the next logical method call(s) are made available. | {{yes}} | {{yes}} | {{yes}} |- | [[Interpreter pattern|Interpreter]] | Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. | {{yes}} | {{yes}} | {{yes}} |- | [[Iterator pattern|Iterator]] | Provide a way to access the elements of an [[Aggregate pattern|aggregate]] object sequentially without exposing its underlying representation. | {{yes}} | {{yes}} | {{yes}} |- | [[Mediator pattern|Mediator]] | Define an object that encapsulates how a set of objects interact. Mediator promotes [[loose coupling]] by keeping objects from referring to each other explicitly, and it allows their interaction to vary independently. | {{yes}} | {{yes}} | {{yes}} |- | [[Memento pattern|Memento]] | Without violating encapsulation, capture and externalize an object's internal state allowing the object to be restored to this state later. | {{yes}} | {{yes}} | {{yes}} |- | [[Null object]] | Avoid null references by providing a default object. | {{yes}} | {{yes}} | {{yes}} |- | [[Observer pattern|Observer]] or [[Publish/subscribe]] | Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically. | {{yes}} | {{yes}} | {{yes}} |- | [[Design pattern Servant|Servant]] | Define common functionality for a group of classes. The servant pattern is also frequently called helper class or utility class implementation for a given set of classes. The helper classes generally have no objects hence they have all static methods that act upon different kinds of class objects. | {{yes}} | {{yes}} | {{yes}} |- | [[Specification pattern|Specification]] | Recombinable [[business logic]] in a [[Boolean algebra|Boolean]] fashion. | {{yes}} | {{yes}} | {{yes}} |- | [[State pattern|State]] | Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. | {{yes}} | {{yes}} | {{yes}} |- | [[Strategy pattern|Strategy]] | Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. | {{yes}} | {{yes}} | {{yes}} |- | [[Template method]] | Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. | {{yes}} | {{yes}} | {{yes}} |- | [[Visitor pattern|Visitor]] | Represent an operation to be performed on instances of a set of classes. Visitor lets a new operation be defined without changing the classes of the elements on which it operates. | {{yes}} | {{yes}} | {{yes}} |} === [[Concurrency patterns]] === {| class="wikitable" |- ! Name ! Description ! In ''[[Pattern-Oriented Software Architecture|POSA2]]''<ref name="POSA2">{{cite book | first1 = Douglas C. | last1 = Schmidt | first2 = Michael | last2 = Stal | first3 = Hans | last3 = Rohnert | first4 = Frank | last4 = Buschmann | date = 2000 | title = Pattern-Oriented Software Architecture, Volume 2: Patterns for Concurrent and Networked Objects | publisher = John Wiley & Sons | isbn = 978-0-471-60695-6 }}</ref> ! Other |- | [[Active Object]] | Decouples method execution from method invocation that reside in their own thread of control. The goal is to introduce concurrency, by using [[asynchronous method invocation]] and a [[scheduling (computing)|scheduler]] for handling requests. | {{yes}} | {{n/a}} |- | [[Balking pattern|Balking]] | Only execute an action on an object when the object is in a particular state. | {{no}} | {{n/a}} |- | [[Binding properties pattern|Binding properties]] | Combining multiple observers to force properties in different objects to be synchronized or coordinated in some way.<ref>[http://c2.com/cgi/wiki?BindingProperties Binding Properties<!-- Bot generated title -->]</ref> | {{no}} | {{n/a}} |- | [[Compute kernel]] | The same calculation many times in parallel, differing by integer parameters used with non-branching pointer math into shared arrays, such as [[GPU]]-optimized [[Matrix multiplication]] or [[Convolutional neural network]]. | {{no}} | {{n/a}} |- | [[Double-checked locking]] | Reduce the overhead of acquiring a lock by first testing the locking criterion (the 'lock hint') in an unsafe manner; only if that succeeds does the actual locking logic proceed. Can be unsafe when implemented in some language/hardware combinations. It can therefore sometimes be considered an [[anti-pattern]]. | {{yes}} | {{n/a}} |- | [[Event-Based Asynchronous Pattern|Event-based asynchronous]] | Addresses problems with the asynchronous pattern that occur in multithreaded programs.<ref name="PC#2008">{{cite book|title = Professional C# 2008| first1 = Christian | last1 = Nagel | first2 = Bill | last2 = Evjen | first3 = Jay | last3 = Glynn | first4 = Karli | last4 = Watson | first5 = Morgan | last5 = Skinner|pages = 570–571|publisher = Wiley|year = 2008|isbn = 978-0-470-19137-8|chapter = Event-based Asynchronous Pattern}}</ref> | {{no}} | {{n/a}} |- | [[Guarded suspension]] | Manages operations that require both a lock to be acquired and a precondition to be satisfied before the operation can be executed. | {{no}} | {{n/a}} |- | [[Join-pattern|Join]] | Join-pattern provides a way to write concurrent, parallel and distributed programs by message passing. Compared to the use of threads and locks, this is a high-level programming model. | {{no}} | {{n/a}} |- | [[Lock (computer science)|Lock]] | One thread puts a "lock" on a resource, preventing other threads from accessing or modifying it.<ref>[http://c2.com/cgi/wiki?LockPattern Lock Pattern<!-- Bot generated title -->]</ref> | {{no}} | {{yes|PoEAA<ref name = "PoEAA"/>}} |- | [[Messaging pattern|Messaging design pattern (MDP)]] | Allows the interchange of information (i.e. messages) between components and applications. | {{no}} | {{n/a}} |- | [[Monitor (synchronization)|Monitor object]] | An object whose methods are subject to [[mutual exclusion]], thus preventing multiple objects from erroneously trying to use it at the same time. | {{yes}} | {{n/a}} |- | [[Reactor pattern|Reactor]] | A reactor object provides an asynchronous interface to resources that must be handled synchronously. | {{yes}} | {{n/a}} |- | [[Read-write lock]] | Allows concurrent read access to an object, but requires exclusive access for write operations. An underlying semaphore might be used for writing, and a [[Copy-on-write]] mechanism may or may not be used. | {{no}} | {{n/a}} |- | [[Scheduler pattern|Scheduler]] | Explicitly control when threads may execute single-threaded code. | {{no}} | {{n/a}} |- | Service handler pattern | For each request, a server spawns a dedicated client handler to handle a request.<ref>{{cite journal |last1=Francalanza |first1=Adrian |last2=Tabone |first2=Gerard |title=ElixirST: A session-based type system for Elixir modules |journal=Journal of Logical and Algebraic Methods in Programming |date=October 2023 |volume=135 |doi=10.1016/j.jlamp.2023.100891|s2cid=251442539 }}</ref> Also referred to as ''thread-per-session''.<ref>{{cite journal |last1=Schmidt |first1=Douglas C. |last2=Vinoski |first2=Steve |title=Object Interconnections: Comparing Alternative Programming Techniques for Multi-threaded CORBA Servers (Column 7) |date=July–August 1996 |journal=SIGS C++ Report |url=https://www.dre.vanderbilt.edu/~schmidt/PDF/C++-report-col7.pdf |s2cid=2654843}}</ref> | {{no}} | {{n/a}} |- | [[Thread pool]] | A number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads. Can be considered a special case of the [[object pool]] pattern. | {{no}} | {{n/a}} |- | [[Thread-specific storage]] | Static or "global" memory local to a thread. | {{yes}} | {{n/a}} |- | Safe Concurrency with Exclusive Ownership | Avoiding the need for runtime concurrent mechanisms, because exclusive ownership can be proven. This is a notable capability of the Rust language, but compile-time checking isn't the only means, a programmer will often manually design such patterns into code - omitting the use of locking mechanism because the programmer assesses that a given variable is never going to be concurrently accessed. | {{no}} | {{n/a}} |- | CPU atomic operation | x86 and other CPU architectures support a range of atomic instructions that guarantee memory safety for modifying and accessing primitive values (integers). For example, two threads may both increment a counter safely. These capabilities can also be used to implement the mechanisms for other concurrency patterns as above. The [[C Sharp (programming language)|C#]] language uses the [https://docs.microsoft.com/en-us/dotnet/api/system.threading.interlocked?view=net-5.0 Interlocked] class for these capabilities. | {{no}} | {{n/a}} |} ==Documentation== The documentation for a design pattern describes the context in which the pattern is used, the forces within the context that the pattern seeks to resolve, and the suggested solution.<ref name = "GabrielHillside">{{cite web | first = Dick | last = Gabriel | author-link = Richard P. Gabriel | title = A Pattern Definition | url = http://hillside.net/patterns/definition.html | access-date = 2007-03-06 |archive-url = https://web.archive.org/web/20070209224120/http://hillside.net/patterns/definition.html <!-- Bot retrieved archive --> | archive-date = 2007-02-09}}</ref> There is no single, standard format for documenting design patterns. Rather, a variety of different formats have been used by different pattern authors. However, according to [[Martin Fowler (software engineer)|Martin Fowler]], certain pattern forms have become more well-known than others, and consequently become common starting points for new pattern-writing efforts.<ref name = "Fowler2006">{{cite web | first = Martin | last = Fowler | author-link = Martin Fowler (software engineer) | title = Writing Software Patterns | url = http://www.martinfowler.com/articles/writingPatterns.html | date = 2006-08-01 | access-date = 2007-03-06 }}</ref> One example of a commonly used documentation format is the one used by [[Erich Gamma]], [[Richard Helm]], [[Ralph Johnson (computer scientist)|Ralph Johnson]], and [[John Vlissides]] in their book ''[[Design Patterns]]''. It contains the following sections: *'''Pattern Name and Classification:''' A descriptive and unique name that helps in identifying and referring to the pattern. *'''Intent:''' A description of the goal behind the pattern and the reason for using it. *'''Also Known As:''' Other names for the pattern. *'''Motivation (Forces):''' A scenario consisting of a problem and a context in which this pattern can be used. *'''Applicability:''' Situations in which this pattern is usable; the context for the pattern. *'''Structure:''' A graphical representation of the pattern. [[Unified Modeling Language#UML Class Diagram|Class diagram]]s and [[Interaction diagram]]s may be used for this purpose. *'''Participants:''' A listing of the classes and objects used in the pattern and their roles in the design. *'''Collaboration:''' A description of how classes and objects used in the pattern interact with each other. *'''Consequences:''' A description of the results, side effects, and trade offs caused by using the pattern. *'''Implementation:''' A description of an implementation of the pattern; the solution part of the pattern. *'''Sample Code:''' An illustration of how the pattern can be used in a programming language. *'''Known Uses:''' Examples of real usages of the pattern. *'''Related Patterns:''' Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns. ==Criticism== Some suggest that design patterns may be a sign that features are missing in a given programming language ([[Java (programming language)|Java]] or [[C++]] for instance). [[Peter Norvig]] 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 (programming language)|Lisp]] or [[Dylan (programming language)|Dylan]].<ref name="Norvig1998">{{cite conference | last = Norvig | first = Peter | author-link = Peter Norvig | title = Design Patterns in Dynamic Languages | url = http://www.norvig.com/design-patterns/ | year = 1998}}</ref> Related observations were made by Hannemann and Kiczales who implemented several of the 23 design patterns using an [[Aspect-oriented programming|aspect-oriented programming language]] (AspectJ) and showed that code-level dependencies were removed from the implementations of 17 of the 23 design patterns and that aspect-oriented programming could simplify the implementations of design patterns.<ref name="Hannemann2002">{{cite conference | last1 = Hannemann | first1 = Jan | last2 = Kiczales | first2 = Gregor | book-title = Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications - OOPSLA '02 | author-link2 = Gregor Kiczales | title = Design pattern implementation in Java and AspectJ | year = 2002 | page = 161 | conference = OOPSLA '02 | doi = 10.1145/582419.582436 | isbn = 1581134711 }}</ref> See also [[Paul Graham (computer programmer)|Paul Graham's]] essay "Revenge of the Nerds".<ref name="Graham2002">{{cite web | last = Graham | first = Paul | author-link = Paul Graham (computer programmer) | title = Revenge of the Nerds | url = http://www.paulgraham.com/icad.html | year = 2002 | access-date = 2012-08-11}} </ref> Inappropriate use of patterns may unnecessarily increase complexity.<ref name="CodeComplete2">{{cite book | last = McConnell | first = Steve | title = Code Complete: A Practical Handbook of Software Construction, 2nd Edition | url = https://archive.org/details/codecomplete0000mcco | url-access = registration | year = 2004 | page = [https://archive.org/details/codecomplete0000mcco/page/105 105]| publisher = Pearson Education | isbn = 9780735619678 }} </ref> [https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition FizzBuzzEnterpriseEdition] offers a humorous example of over-complexity introduced by design patterns.<ref name="Kragbæk2016">{{cite web | last = Kragbæk | first = Mikael | title = FizzBuzzEnterpriseEdition | url = https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition | access-date = 2024-11-19}} </ref> By definition, a pattern must be programmed anew into each application that uses it. Since some authors see this as a step backward from [[software reuse]] as provided by [[software componentry|components]], researchers have worked to turn patterns into components. Meyer and Arnout were able to provide full or partial componentization of two-thirds of the patterns they attempted.<ref name = "Meyer2006">{{cite journal | first1 = Bertrand | last1 = Meyer | author-link = Bertrand Meyer | first2 = Karine | last2 = Arnout | title = Componentization: The Visitor Example | journal = [[IEEE Computer]] | volume = 39 | issue = 7 | pages = 23–30 |date=July 2006 | url = http://se.ethz.ch/~meyer/publications/computer/visitor.pdf | doi = 10.1109/MC.2006.227 | citeseerx = 10.1.1.62.6082 | s2cid = 15328522 }}</ref> In order to achieve flexibility, design patterns may introduce additional levels of [[indirection]], which may complicate the resulting design and decrease [[Runtime (program lifecycle phase)|runtime]] performance. == Relationship to other topics == Software design patterns offer finer granularity compared to software architecture patterns and software architecture styles, as design patterns focus on solving detailed, low-level design problems within individual components or subsystems. Examples include Singleton, Factory Method, and Observer. <ref name="O'Reilly Media">{{Cite book |title=Fundamentals of Software Architecture: An Engineering Approach |publisher=O'Reilly Media |year=2020 |isbn=978-1492043454}}</ref><ref name=":0">{{Cite book |title=Design Patterns: Elements of Reusable Object-Oriented Software |isbn=978-0201633610}}</ref><ref name=":1">{{Cite book |title=Patterns of Enterprise Application Architecture |isbn=978-0321127426}}</ref> [[List of software architecture styles and patterns|Software Architecture Pattern]] refers to a reusable, proven solution to a recurring problem at the system level, addressing concerns related to the overall structure, component interactions, and quality attributes of the system.{{Citation needed|date=January 2025}} Software architecture patterns operate at a higher level of abstraction than design patterns, solving broader system-level challenges. While these patterns typically affect system-level concerns, the distinction between architectural patterns and architectural styles can sometimes be blurry. Examples include [[Circuit breaker design pattern|Circuit Breaker]]. <ref name="O'Reilly Media" /><ref name=":0" /><ref name=":1" /> [[List of software architecture styles and patterns|Software Architecture Style]] refers to a high-level structural organization that defines the overall system organization, specifying how components are organized, how they interact, and the constraints on those interactions.{{Citation needed|date=January 2025}} Architecture styles typically include a vocabulary of component and connector types, as well as semantic models for interpreting the system's properties. These styles represent the most coarse-grained level of system organization. Examples include [[Multitier architecture|Layered Architecture]], [[Microservices]], and [[Event-driven architecture|Event-Driven Architecture]]. <ref name="O'Reilly Media" /><ref name=":0" /><ref name=":1" /> ==See also== {{Div col|colwidth=22em}} *[[Abstraction principle (programming)|Abstraction principle]] *[[Algorithmic skeleton]] *[[Anti-pattern]] *[[Architectural pattern]] *[[Canonical protocol pattern]] *[[Debugging patterns]] *[[Design pattern]] *[[Distributed design patterns]] *[[Double-chance function]] *[[Enterprise Architecture framework]] *[[GRASP (object-oriented design)]] *[[Helper class]] *[[Programming idiom|Idiom]] in programming *[[Interaction design pattern]] *[[List of software architecture styles and patterns]] *[[List of software development philosophies]] *[[List of software engineering topics]] *[[Pattern language]] *[[Pattern theory]] *[[Pedagogical patterns]] *[[Portland Pattern Repository]] *[[Refactoring]] *[[Software development methodology]] {{div col end}} ==References== {{reflist|30em}} ==Further reading== {{Refbegin}} * {{cite book |last1=Alexander |first1=Christopher |author1-link=Christopher Alexander |last2=Ishikawa |first2=Sara |last3=Silverstein |first3=Murray |last4=Jacobson |first4=Max |last5=Fiksdahl-King |first5=Ingrid |last6=Angel |first6=Shlomo |date=1977 |title=A Pattern Language: Towns, Buildings, Construction |publisher=Oxford University Press |isbn=978-0-19-501919-3 |location=New York |title-link=A Pattern Language: Towns, Buildings, Construction }} * {{cite book |last1=Alur |first1=Deepak |last2=Crupi |first2=John |last3=Malks |first3=Dan |date=May 2003 |title=Core J2EE Patterns: Best Practices and Design Strategies |publisher=[[Prentice Hall]] |isbn=978-0-13-142246-9 |edition=2nd }} * {{cite book |last1=Beck |first1=Kent |author1-link=Kent Beck |date=October 2007 |title=Implementation Patterns |publisher=[[Addison-Wesley]] |isbn=978-0-321-41309-3 }} * {{cite book |last1=Beck |first1=Kent |author1-link=Kent Beck |last2=Crocker |first2=R. |last3=Meszaros |first3=G. |last4=Coplien |first4=J. O. |author4-link=James O. Coplien |last5=Dominick |first5=L. |last6=Paulisch |first6=F. |last7=Vlissides |first7=J. |author7-link=John Vlissides |date=March 1996 |title=Proceedings of the 18th International Conference on Software Engineering |pages=25–30 }} * {{cite book |last1=Borchers |first1=Jan |year=2001 |title=A Pattern Approach to Interaction Design |publisher=[[John Wiley & Sons]] |isbn=978-0-471-49828-5 }} * {{cite book |last1=Coplien |first1=James O. |author1-link=Jim Coplien |last2=Schmidt |first2=Douglas C. |date=1995 |title=Pattern Languages of Program Design |publisher=[[Addison-Wesley]] |isbn=978-0-201-60734-5 }} * {{cite book |last1=Coplien |first1=James O. |author1-link=Jim Coplien |last2=Vlissides |first2=John M. |author2-link=John Vlissides |last3=Kerth |first3=Norman L. |date=1996 |title=Pattern Languages of Program Design 2 |publisher=[[Addison-Wesley]] |isbn=978-0-201-89527-8 }} * {{Cite book |last1=Eloranta |first1=Veli-Pekka |last2=Koskinen |first2=Johannes |last3=Leppänen |first3=Marko |last4=Reijonen |first4=Ville |year=2014 |title=Designing Distributed Control Systems: A Pattern Language Approach |publisher=Wiley |isbn=978-1118694152}} * {{cite book |last1=Fowler |first1=Martin |author1-link=Martin Fowler (software engineer) |year=1997 |title=Analysis Patterns: Reusable Object Models |publisher=[[Addison-Wesley]] |isbn=978-0-201-89542-1 }} * {{cite book |last1=Fowler |first1=Martin |author1-link=Martin Fowler (software engineer) |year=2003 |title=Patterns of Enterprise Application Architecture |publisher=[[Addison-Wesley]] |isbn=978-0-321-12742-6 }} * {{cite book |last1=Freeman |first1=Eric |last2=Freeman |first2=Elisabeth |last3=Sierra |first3=Kathy |author3-link=Kathy Sierra |last4=Bates |first4=Bert |date=2004 |title=Head First Design Patterns |publisher=[[O'Reilly Media]] |isbn=978-0-596-00712-6 }} * {{cite book |last1=Hohmann |first1=Luke |last2=Fowler |first2=Martin |author2-link=Martin Fowler (software engineer) |last3=Kawasaki |first3=Guy |author3-link=Guy Kawasaki |year=2003 |publisher=[[Addison-Wesley]] |title=Beyond Software Architecture |isbn=978-0-201-77594-5 }} * {{cite book |last1=Gabriel |first1=Richard |author1-link=Richard P. Gabriel |year=1996 |url=http://www.dreamsongs.com/NewFiles/PatternsOfSoftware.pdf |title=Patterns of Software: Tales From The Software Community |publisher=[[Oxford University Press]] |isbn=978-0-19-512123-0 |page=235 |archive-url=https://web.archive.org/web/20030801111358/http://dreamsongs.com/NewFiles/PatternsOfSoftware.pdf |archive-date=2003-08-01 }} * {{cite book |last1=Gamma |first1=Erich |author1-link=Erich Gamma |last2=Helm |first2=Richard |author2-link=Richard Helm |last3=Johnson |first3=Ralph |author3-link=Ralph Johnson (computer scientist) |last4=Vlissides |first4=John |author4-link=John Vlissides |date=1995 |title=Design Patterns: Elements of Reusable Object-Oriented Software |publisher=[[Addison-Wesley]] |isbn=978-0-201-63361-0 |ref=book_Gamma1995 |title-link=Design Patterns (book) }} * {{cite book |last1=Hohpe |first1=Gregor |last2=Woolf |first2=Bobby |date=2003 |title=Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions |publisher=[[Addison-Wesley]] |isbn=978-0-321-20068-6 |title-link=Enterprise Integration Patterns }} * {{cite book |last1=Holub |first1=Allen |year=2004 |title=Holub on Patterns |publisher=[[Apress]] |isbn=978-1-59059-388-2 }} * {{cite book |last1=Kircher |first1=Michael |last2=Völter |first2=Markus |last3=Zdun |first3=Uwe |date=2005 |title=Remoting Patterns: Foundations of Enterprise, Internet and Realtime Distributed Object Middleware |publisher=[[John Wiley & Sons]] |isbn=978-0-470-85662-8 |url-access=registration |url=https://archive.org/details/remotingpatterns0000volt }} * {{cite book |last1=Larman |first1=Craig |author1-link=Craig Larman |year=2005 |title=Applying UML and Patterns |publisher=[[Prentice Hall]] |isbn=978-0-13-148906-6 }} * {{cite book |last1=Liskov |first1=Barbara |author1-link=Barbara Liskov |last2=Guttag |first2=John |author2-link=John Guttag |date=2000 |title=Program Development in Java: Abstraction, Specification, and Object-Oriented Design |publisher=[[Addison-Wesley]] |isbn=978-0-201-65768-5 }} * {{cite book |last1=Manolescu |first1=Dragos |last2=Voelter |first2=Markus |last3=Noble |first3=James |date=2006 |title=Pattern Languages of Program Design 5 |publisher=[[Addison-Wesley]] |isbn=978-0-321-32194-7 }} * {{cite book |last1=Marinescu |first1=Floyd |year=2002 |title=EJB Design Patterns: Advanced Patterns, Processes and Idioms |publisher=[[John Wiley & Sons]] |isbn=978-0-471-20831-0 |url=https://archive.org/details/ejbdesignpattern00mari }} * {{cite book |last1=Martin |first1=Robert Cecil |author1-link=Robert C. Martin |last2=Riehle |first2=Dirk |last3=Buschmann |first3=Frank |date=1997 |title=Pattern Languages of Program Design 3 |publisher=[[Addison-Wesley]] |isbn=978-0-201-31011-5 }} * {{cite book |last1=Mattson |first1=Timothy G. |last2=Sanders |first2=Beverly A. |last3=Massingill |first3=Berna L. |date=2005 |title=Patterns for Parallel Programming |url=https://archive.org/details/patternsforparal0000matt |url-access=registration |publisher=Addison-Wesley |isbn=978-0-321-22811-6 }} * {{cite book |last1=Shalloway |first1=Alan |last2=Trott |first2=James R. |date=2001 |title=Design Patterns Explained, Second Edition: A New Perspective on Object-Oriented Design |publisher=Addison-Wesley |isbn=978-0-321-24714-8 |url=https://archive.org/details/isbn_9780321247148 }} * {{cite book |last1=Vlissides |first1=John M. |author1-link=John Vlissides |year=1998 |title=Pattern Hatching: Design Patterns Applied |publisher=[[Addison-Wesley]] |isbn=978-0-201-43293-0 }} * {{cite book |last1=Weir |first1=Charles |last2=Noble |first2=James |date=2000 |url=http://www.cix.co.uk/~smallmemory/ |title=Small Memory Software: Patterns for systems with limited memory |publisher=[[Addison-Wesley]] |isbn=978-0-201-59607-6 |archive-url=https://web.archive.org/web/20070617114432/http://www.cix.co.uk/~smallmemory |archive-date=2007-06-17 }} {{Refend}} {{Design patterns}} {{Authority control}} [[Category:Software design patterns| ]] [[Category:Software development]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite conference
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite report
(
edit
)
Template:Cite thesis
(
edit
)
Template:Cite web
(
edit
)
Template:Design patterns
(
edit
)
Template:Div col
(
edit
)
Template:Div col end
(
edit
)
Template:N/a
(
edit
)
Template:No
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Yes
(
edit
)