A software design pattern is a template for how to solve a problem that can be used in many different situations. It is a formalised best practice that a programmer can use to solve common problems when designing an application.
Design patterns are categorised into four sub-classifications based on kind of problem they solve. Creational patterns provide the capability to create objects based on a required criteria and in a controlled way. Structural patterns are about organising different classes and objects to form larger structures and provide new functionality. Behavioural patterns are about identifying common communication patterns between objects and realise these patterns. Finally, concurrency patterns are those types of design patterns that deal with the multi-threaded programming paradigm.
Creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or in added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
Five well-known design patterns that are parts of creational patterns are the:
Abstract Factory Pattern
The abstract factory pattern provides an interface for creating related or dependent objects without specifying the objects’ concrete classes.
Builder Pattern
The builder pattern separates the construction of a complex object from its representation so that the same construction process can create different representations.
Factory Method Pattern
The factory method pattern allows a class to defer instantiation to subclasses.
Prototype Pattern
The prototype pattern specifies the kind of object to create using a prototypical instance and creates new objects by cloning this prototype.
Singleton Pattern
The singleton pattern ensures that a class only has one instance and provides a global point of access to it.
Structural design patterns are design patterns that ease the design by identifying a simple way to realise relationships among entities.
Examples of Structural Patterns include:
Adapter Pattern
The adapter pattern adapts one interface for a class into one that a client expects.
Bridge Pattern
The bridge pattern decouples an abstraction from its implementation so that the two can vary independently.
Marker Pattern
The marker pattern makes use of an empty interface to associate metadata with a class.
Composite Pattern
The composite pattern is a tree structure of objects where every object has the same interface.
Flyweight Pattern
The flyweight pattern saves space by making a large quantity of objects share a common properties object.
Behavioural design patterns are design patterns that identify common communication patterns among objects and realise these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
Examples of this type of design pattern include:
Observer Pattern
The observer pattern a.k.a. Event Listener registers Objects to observe an event that may be fired by another object.
Null Object Pattern
Null object pattern is designed to act as a default value of an object.
Memento Pattern
The memento pattern provides the ability to restore an object to its previous state (rollback)
Command Pattern
The command pattern encapsulates an action from its parameters.
Chain of Responsibility Pattern
The chain of responsibility pattern passes the command objects to to other objects by logic-containing processing objects.
Concurrency patterns are those types of design patterns that deal with the multi-threaded programming paradigm.
Examples of this class of patterns include:
Thread Pool Pattern
The thread pool pattern a.k.a. worker-crew model maintains multiple threads waiting for tasks to be allocated for concurrent execution by the supervising program.
Scheduler Pattern
The scheduler pattern is a pattern by which work is assigned to resources that complete the work.
Read Write Lock Pattern
A read write lock pattern is a synchronisation primitive that solves one of the readers–writers problems. An RWL allows concurrent access for read-only operations, while write operations require exclusive access.
Reactor Pattern
The reactor pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.
Design patterns may be viewed as a structured approach to computer programming intermediate between the levels of a programming paradigm and a concrete algorithm. One can use multiple patterns in a single application, this is why it is very important to design the software before starting the project.