Design Patterns are like quick recipe of software design. This page represents a Cheat sheet or Gang of Four Design Patterns summary.
Table of Contents
Please Note
This page just gives a high-level Design Patterns summary to quickly revise the Topic. If you never read Design Patters, please read them separately.
Also check for the link of Design Pattern name. I’ll soon be adding the details of every Desing Pattern.
What are Design Patterns?
A Design Pattern is a reusable solution to common Software Engineering problems.
We can compare it with recipe. Suppose we want to cook a particular dish, simply get its recipe and cook it. Similarly, there are lot of common Software Engineering problems, that are common in most of the projects. Design Patterns are like the recipe or solutions to those common Software Engineering problems.
What is Gang of Four?
Gang of Four are four authors – Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides who wrote the book “Design Patterns: Elements of Reusable Object-Oriented Software“.
The book or Gang of Four Design Patterns, covered as book 5 in my recommendation of 10 must read books for a Software Engineers, includes 23 Design Patterns in three categories:
Creational Design Patterns
Patterns dealing with the object creation mechanisms, in a manner suitable to the situation.
- Singleton: Ensures that only one instance of a class is created and provides a global point of access to it.
- Factory method: Allows a class to delegate the instantiation process to subclasses.
- Abstract factory: Provides an interface for creating families of related or dependent objects without specifyingtheir concrete classes.
- Builder: Separates the construction of a complex object from its representation so that the same construction process can create different representations.
- Prototype: This allows an object to create customized objects without knowing their class or the details of how they are created.
Structural Design Patterns
Structural design patterns focus on how classes and objects are composed to form larger structures and ensure if we need to change one part of the system, it won’t disrupt the entire system.
- Adapter: Works like a bridge between two incompatible interfaces. It combines the capability of two independent interfaces.
- Bridge: Decouples an abstraction from its implementation so that the two can vary independently. It decouples the implementation class and abstract class by providing a bridge structure between them.
- Composite: Used where we need to treat a group of objects in a similar way as a single object. This pattern composes objects in term of a tree structure to represent part as well as a whole hierarchy.
- Decorator: Allows a user to add new functionality to an existing object without altering its structure. It acts as a wrapper to the existing class.
- Façade: Hides the complexities of the system and provides an interface to the client using which the client can access the system by adding an interface to an existing system to hide its complexities
- Flyweight: Reduces the number of objects created, to decrease memory footprint and increase performance and deal with objects at a low level of system structure.
- Proxy: It is used to make a class represents the functionality of another class.
Behavioural Design Patterns
Behavioural design Patterns focus on the communication between objects. These patterns ensure that if we need to change the behaviour of one part of the system, it won’t disrupt the entire system. They hide the complicated details of how we manage interactions.
- Chain or Responsibility: Decouples sender and receiver of a request based on the type of request.
- Command: Encapsulates a request as an object, thereby letting users parameterize clients with queues, requests, and operations.
- Interpreter Pattern: Provides a way to evaluate language grammar or expression.
- Iterator Pattern: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- Mediator Pattern: Reduces communication complexity between multiple objects or classes. It provides a mediator class that handles all the communications between different classes and supports loose coupling.
- Memento Pattern: Saves and restores the internal state of an object without violating encapsulation.
- Observer Pattern: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- State Pattern: Allows an object to alter its behaviour when its internal state changes. The object will appear to change its class.
- Strategy Pattern: Defines a family of algorithms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Template Pattern: Defines 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.
- Visitor Pattern: Lets you define a new operation without changing the classes of the elements on which it operates.
Please Note: This is just a quick one-liner Gang of Four Design Patterns summary, so a quick recall of what you have already studies. If you need details with example, keep following this page, as I’ll be soon adding details of every design pattern, with easy-to-follow examples in multiple programming languages.