The three main categories of design patterns are:
1. Creational patterns: These patterns deal with the process of object creation. They aim to establish the best way to create objects to suit specific requirements. Creational patterns include:
- Singleton Pattern
- Factory Pattern
- Abstract Factory Pattern
- Builder Pattern
- Prototype Pattern
2. Structural patterns: These patterns focus on object composition, i.e., how classes and objects are designed to form larger structures. Structural patterns include:
- Adapter Pattern
- Bridge Pattern
- Composite Pattern
- Decorator Pattern
- Facade Pattern
- Flyweight Pattern
- Proxy Pattern
3. Behavioral patterns: These patterns are associated with how objects communicate and collaborate with each other at runtime. Behavioral patterns include:
- Chain of Responsibility Pattern
- Command Pattern
- Interpreter Pattern
- Iterator Pattern
- Mediator Pattern
- Memento Pattern
- Observer Pattern
- State Pattern
- Strategy Pattern
- Template Method Pattern
- Visitor Pattern
I will provide a brief explanation of each of the types of design patterns:
**1. Creational Patterns**
These patterns are concerned with the process of object creation. They deal with the best way to create objects to suit specific requirements. The creational pattern is essential when creating objects that are complex and require a lot of setup. It is used to hide the details of object creation from the client, so the client doesn’t have to worry about these details. The five types of creational design patterns are as follows:
- **Singleton Pattern**
The Singleton pattern ensures that a class has only one instance, and provides a global point of access to that instance. This pattern involves a single class, which is responsible for creating its own object, and providing access to the instance to the entire system.
- **Factory Pattern**
The Factory pattern is a creational pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. This pattern allows a class to decide which class to instantiate at runtime.
- **Abstract Factory Pattern**
The Abstract Factory pattern is a creational pattern that provides an interface for creating related objects without specifying their concrete classes. This pattern involves a hierarchy of factories, where each factory returns a different set of related objects.
- **Builder Pattern**
The Builder pattern is a creational pattern that separates the construction of a complex object from its representation. This pattern allows you to create different representations of an object using the same construction process.
- **Prototype Pattern**
The Prototype pattern is a creational pattern that allows you to create new forms of an object by cloning from an existing instance of that object. This pattern uses an existing object as a prototype and creates a new object by copying the existing object.
**2. Structural Patterns**
Structural patterns deal with object composition. They aim to make it easier to combine objects into larger structures. The structural pattern describes how classes and objects are designed to form larger structures. It provides the building blocks for an application, allowing different parts of the application to work together. The seven types of structural design patterns are as follows:
- **Adapter Pattern**
The Adapter pattern converts one interface into another that the client expects. This pattern is useful when you want to make an existing class work with another class, but its interface does not match.
- **Bridge Pattern**
The Bridge pattern decouples an abstraction from its implementation. This pattern involves an abstraction that depends on an implementation, but allows the implementation to change without affecting the abstraction.
- **Composite Pattern**
The Composite pattern treats objects as a group or a single object in the same manner. This pattern involves creating a tree-like structure where a group of objects is treated the same way as a single object.
- **Decorator Pattern**
The Decorator pattern adds new functionality to an existing object without changing its structure. This pattern involves a decorator class that wraps an existing class and provides additional functionality without changing the existing class.
- **Facade Pattern**
The Facade pattern provides a simple interface to a complex subsystem. This pattern involves creating a class that provides a simple interface to a complex subsystem.
- **Flyweight Pattern**
The Flyweight pattern conserves memory by sharing large numbers of similar objects. This pattern involves dividing an object into two parts: a state-dependent part and a state-independent part. The state-independent part can be shared among many instances of the object.
- **Proxy Pattern**
The Proxy pattern provides a placeholder for another object to control access to it. This pattern involves creating a proxy class that represents the functionality of another class. The proxy is used to control access to the other class.
**3. Behavioral Patterns**
Behavioral patterns deal with communication between objects. They describe how objects interact with each other and how they operate together to create complex systems. It provides the communication patterns between objects in a system. The behavioral pattern describes how different objects interact and operate together. The eleven types of behavioral design patterns are as follows:
- **Chain of Responsibility Pattern**
The Chain of Responsibility pattern allows an object to send a request to a chain of objects. This pattern involves a chain of objects, and each object in the chain can either handle the request or pass it on to the next object in the chain.
- **Command Pattern**
The Command pattern creates objects that encapsulate actions and parameters. This pattern involves creating a command interface and a command class. The command class has all the information needed to execute an action.
- **Interpreter Pattern**
The Interpreter pattern is used to convert a certain value to another value. This pattern involves creating an interpreter that can parse and interpret expressions in a language.
- **Iterator Pattern**
The Iterator pattern provides a way to access the elements of an object without exposing its underlying implementation. This pattern involves creating an iterator class that provides a way to access the elements of an object.
- **Mediator Pattern**
The Mediator pattern defines an object that encapsulates the communication between objects. This pattern involves creating a mediator object that encapsulates the communication between objects.
- **Memento Pattern**
The Memento pattern provides a way to restore an object to its previous state. This pattern involves creating a memento object that encapsulates the state of an object.
- **Observer Pattern**
The Observer pattern provides a way to notify objects when a change occurs. This pattern involves creating an observer interface and an observer class. The observer class can register with the subject to receive notifications.
- **State Pattern**
The State pattern allows an object to change its behavior when its internal state changes. This pattern involves creating a state interface and a state class. The state class represents the different states of an object.
- **Strategy Pattern**
The Strategy pattern allows a client to choose an algorithm from a family of algorithms at runtime. This pattern involves creating a strategy interface and multiple strategy classes. The client sets the strategy at runtime.
- **Template Method Pattern**
The Template Method pattern provides a way to define the skeleton of an algorithm in a superclass, but allow subclasses to override specific steps. This pattern involves creating an abstract class that defines the template method, which calls abstract methods that are defined by subclasses.
- **Visitor Pattern**
The Visitor pattern separates an algorithm from an object structure. This pattern involves creating a visitor interface and a visitor class. The visitor class can visit different objects and perform different operations on them.