Types of patterns:
- creational
- structural
- behavioral
Creational:
Singleton — restricts the creation of a class to a single instance, and provides access to that single instance.
Factory — used when we have a superclass with multiple subclasses and we need to return a subclass based on input.
Abstract factory — uses a super factory to create factories, which we then use to create objects.
Builder — used to create complex objects using simple objects. It gradually creates a large object from a small, simple object.
Prototype — helps improve performance when creating duplicate objects; instead of creating a new object, it creates and returns a clone of an existing object.
Structural:
Adapter — a converter between two incompatible objects. We can use the adapter pattern to combine two incompatible interfaces.
Composite — uses one class to represent a tree structure.
Proxy — provides the functionality of another class.
Flyweight — reuses objects instead of creating a large number of similar objects.
Facade — provides a simple interface for a client, which uses the interface to interact with the system.
Bridge — makes specific classes independent from classes implementing an interface.
Decorator — adds new functionality to an existing object without tying into its structure.
Behavioral:
Template method — defines a basic algorithm and allows descendants to override some steps of the algorithm without changing its overall structure.
Mediator — provides an intermediary class that handles all communication between different classes.
Chain of responsibility — makes it possible to avoid strict dependence between the sender and receiver of a request; moreover, the request can be processed by several objects.
Observer — allows one object to monitor and respond to events occurring in other objects.
Strategy — allows for strategies (algorithms) to be changed at run time.
Command — an interface that declares a method for performing a specific action.
State — allows an object to change its behavior depending on its state.
Visitor — used to simplify operations on groups of related objects.
Interpreter — defines a grammar for a simple language in the problem domain.
Iterator — sequentially accesses elements of a collection without knowing its underlying form.
Memento — used to store an object's state; this state can be restored later.
More reading: |
---|
GO TO FULL VERSION