- What is
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. 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.
Design patterns may be viewed as a structured approach to computer programming intermediate between the levels of a programming paradigm and a concrete algorithm.
- Creational design patterns
Name | Category | Description | Remark |
---|---|---|---|
Abstract Factory | Creational | Creates an instance of several families of classes | - |
Builder | Creational | Separates object construction from its representation | - |
Factory Method | Creational | Creates an instance of several derived classes | - |
Object Pool | Creational | Avoid expensive acquisition and release of resources by recycling objects that are no longer in use | - |
Prototype | Creational | A fully initialized instance to be copied or cloned | - |
Singleton | Creational | A class of which only a single instance can exist | - |
- Structural design patterns
Name | Category | Description | Remark |
---|---|---|---|
Adapter | Structural | Match interfaces of different classes | - |
Bridge | Structural | Separates object construction from its representation | - |
Composite | Structural | A tree structure of simple and composite objects | - |
Decorator | Structural | Add responsibilities to objects dynamically | - |
Facade | Structural | A single class that represents an entire subsystem | - |
Flyweight | Structural | A fine-grained instance used for efficient sharing | - |
Private Class Data | Structural | Restricts accessor/mutator access | - |
Proxy | Structural | An object representing another object | - |
- Behavioral design patterns
Name | Category | Description | Remark |
---|---|---|---|
Chain of responsibility | Behavioral | A way of passing a request between a chain of objects | - |
Command | Behavioral | Encapsulate a command request as an object | - |
Interpreter | Behavioral | A way to include language elements in a program | - |
Iterator | Behavioral | Sequentially access the elements of a collection | - |
Mediator | Behavioral | Defines simplified communication between classes | - |
Memento | Behavioral | Capture and restore an object’s internal state | - |
Null Object | Behavioral | Designed to act as a default value of an object | - |
Observer | Behavioral | A way of notifying change to a number of classes | - |
State | Behavioral | Alter an object’s behavior when its state changes | - |
Strategy | Behavioral | Encapsulates an algorithm inside a class | - |
Template method | Behavioral | Defer the exact steps of an algorithm to a subclass | - |
Visitor | Behavioral | Defines a new operation to a class without change | - |
Reference