A software design pattern is a general reusable solution to a commonly occurring problem within a given context while designing as software.
The design patterns are not a finished design that can be transformed directly into working computer source code. They are template for how solving a problem that can be used in many different situations.
Design patterns are best practices that the programmer can use to solve common problems when designing an application or system. They can also be considered as a structured approach to write the computer programming codes.
Most of object-oriented design patterns typically show relationships and interactions between classes and objects, without specifying the final application classes or objects that are involved.
There are 23 design patterns listed on the book Design Patterns by Gamma et al. and they are classified in three categories: Creational, Structural and Behavioral patterns. But, there are more categories like architectural desing pattern that may be applied at the architecture level of the software such as the Model–View–Controller pattern. All categories of design pattern can be found here.
Here, we are going to discuss about only those design patterns that one find useful while developing software in gerneral cases.
1. Creational Design Pattern
These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case. The most important design patterns under this category are:
- Singleton Pattern – ensures a class has only one instance, and provide a global point of access to it.
- Factory Method Pattern – lets a class defer instantiation to subclasses by defining an interface for creating a single object, but letting subclasses decide which class to instantiate.
- Builder Pattern – Separates the construction of a complex object from its representation, allowing the same construction process to create various representations.
2. Structural Design Pattern
These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities. Frequently used patterns under this category are:
- Proxy Pattern – Provides a surrogate or placeholder for another object to control access to it.
- Facade Pattern – Facade defines a higher-level interface that makes the subsystem easier to use and provide a unified interface to a set of interfaces in a subsystem.
- Front Controller Pattern – This pattern relates to the design of Web applications. It provides a centralized entry point for handling requests.
3. Behavioral Design Pattern
These design patterns are specifically concerned with communication between objects.
- Chain of responsibility pattern – Avoids 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.
- Observer Pattern – 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.
- Strategy Pattern – Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Template Pattern – 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.
4. Architectural Design Pattern
A general, reusable solution to a commonly occurring problem in software design within a given context.
Usage of Design Pattern
The following are two main usages of desing patterns in software development.
1. It provides common platform for developers as they provide a standard terminology and are specific to particular scenario. For instance, if all developers are aware that they are using single object pattern, then they can tell each other that how the flow of program is being executed.
2. As design patterns have been evolved over a long period of time and they provide best solutions to certain problems faced during software development. Knowledge of desing patterns helps one to write the code that adheres best practices.
Reference : Design Patterns by Gamma et al.