In the software industry, there are usually recurring problems that every other firm faces during their development lifecycles. Hundreds of these problems have been identified, and in response to this, industry-leading experts have developed universal solutions for them. These solutions are also known as software design patterns.
Design patterns are solutions to repeated problems in the software industry. They are proven successful methods for constructing types/objects to solve a certain scenario in a program. The Gang of Four (GoF) were the first people who came up with 23 design patterns. They divided them into three categories:
Creational design patterns
Structural design patterns
Behavioral design patterns
Let’s look at each of them in detail:
It houses all the design patterns that are relevant to object creation. These design patterns are responsible for when to instantiate a class to create objects. There are five creational design patterns:
This pattern lets the developer create only a single instance of an object in the entire program. If the program tries to instantiate an object again, the class will return the same object.
In this pattern, the developer creates a factory wrapper class that holds multiple classes. Each class instantiates its object. The developer then uses the factory class to create objects of different classes.
This pattern is similar to the factory pattern. The only difference is instead of instantiating classes. It creates factories that further let the developer instantiate a class.
This pattern separates the creation of a complex object from its representation. It achieves this by letting the developer create an object step by step to get what they want finally.
This pattern helps to create a clone of the provided object. The clone it produces does not depend on its class.
These design patterns are responsible for building relationships between objects to create an efficient structure. It has seven design patterns inside it.
This design pattern acts as an adapter for incompatible interface objects so they can collaborate. It’s useful, especially when the developer wants the objects to communicate.
As the name suggests, this design pattern creates a structure of individual objects and lets the developer use it as a single object.
This structural design pattern lets the developer hide the implementation of the complex object from the client program. In short, it provides an abstraction layer to the underlying logic.
This design pattern creates a wrapper interface on top of existing complex classes. It is particularly useful when integrating an app with existing libraries.
This design pattern also creates a wrapper around an existing object. The wrapper is generally created to enhance the capabilities of the underlying object.
This design pattern is useful when the developer wants to fit multiple objects into the RAM. It does this by sharing the common states between multiple objects.
This design pattern allows the developer to add a placeholder instead of the original object.
There are eleven behavioral design patterns. These patterns deal with the responsibilities and communication patterns among the objects.
This design pattern creates a high-level algorithm that uses different objects. The underlying objects being used can change the specific part of the algorithm.
To establish effective communication, the dependencies between objects need to be reduced. The mediator design pattern acts as a mediator that focuses on reducing these interlinked dependencies.
This design pattern lets the objects subscribe to a particular object to observe its behavior change. Whenever this change happens, the observer pattern instantly lets the subscribed objects know about it.
This pattern lets the developer create a chain of objects. Whenever a request needs to be processed, the program gives it to the first object in the chain. The object decides whether it wants to process it or pass it to the other objects.
This pattern allows an object to change its behavior whenever its internal state changes.
The strategy pattern is used when there are multiple algorithms for a single task. In this case, we put each of them into a separate class and let the client application decide which algorithm to use.
This design pattern wraps a request into an object. This object contains all the information about the request. It is then passed to an invoker object that passes it to another suitable object that can execute this command.
This pattern provides an abstraction around the implementation of saving and restoring the previous state of an object.
The visitor design pattern separates the logic from the object. The logic can then be implemented on multiple similar objects.
This pattern lets the developer access the elements of the object inside of it without revealing the underlying logic.
The last pattern is used to understand a language by defining its grammatical representation. It also provides an interpreter to understand this grammar.
Design patterns help software developers efficiently build products. Instead of doing everything from scratch, they have a guide that helps them solve design problems like experienced developers. These are the original 23 design patterns that Gang of Four introduced. There are hundreds, if not thousands, of design patterns that now exist.
Free Resources