Design Pattern
Also known as: Software design pattern
Reusable, named solution to a commonly recurring problem in software design, described as a template rather than as finished code.
A design pattern is a general, reusable description of how to solve a problem that keeps coming up in software design. Rather than code to be copied, a pattern names a problem, the context in which it arises, a solution structure and its trade-offs. The Observer pattern, for example, lets many objects subscribe to changes in another object and be notified automatically, the basis of many event systems. The Factory pattern centralizes the creation of objects, and the Adapter pattern lets components with incompatible interfaces work together.
The idea came from architecture. Christopher Alexander's 1977 book "A Pattern Language" cataloged recurring solutions in building and town design, and in 1987 Kent Beck and Ward Cunningham presented early work applying pattern languages to programming. The concept reached a wide audience with "Design Patterns: Elements of Reusable Object-Oriented Software" (1994) by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, nicknamed the Gang of Four, which described 23 patterns grouped as creational, structural and behavioral. Cunningham's original wiki, launched in 1995, was created partly to collect patterns.
Patterns give developers a shared vocabulary: saying a component uses a Strategy or a Singleton conveys a design in a word. Architectural patterns such as Model-View-Controller and microservices apply the same thinking at a larger scale. Critics argue that some classic patterns mainly compensate for missing features in languages such as C++ and Java and become unnecessary in languages with first-class functions. Overzealous use can also produce needless complexity, applying patterns because they exist rather than because a problem calls for them. Anti-patterns name common bad solutions to avoid.
Key points
- A design pattern names a recurring problem, its context and a proven solution structure.
- Christopher Alexander's architectural pattern language inspired the idea's adoption in software.
- The 1994 Gang of Four book cataloged 23 object-oriented patterns that became standard vocabulary.
- Applied without need, patterns can add complexity, and some are unnecessary in languages with richer features.
Related entries
Object-Oriented Programming
Programming paradigm that organizes software around objects, which bundle data with the methods that operate on it and interact by sending messages.
Model-View-Controller
Software architecture pattern that separates an application into a data model, views that display it and controllers that handle user input.
Dependency Injection
Technique in which an object receives the components it depends on from outside rather than creating them, making code easier to test and change.
Abstraction
Principle of managing complexity by hiding details behind simpler interfaces, so a component can be used without knowing how it works inside.
Kent Beck
American software engineer who created Extreme Programming, popularized test-driven development and co-wrote the Manifesto for Agile Software Development.
Ward Cunningham
American programmer who created the first wiki, introduced the technical debt metaphor and helped pioneer design patterns and agile methods.
Refactoring
Process of restructuring existing code to improve its design, readability or maintainability without changing its external behavior.
Wiki
Website whose pages authorized users can create and edit collaboratively through a web browser, with revision history and easy linking.
Featured in guides
Referenced by
Other entries that discuss or point to Design Pattern.