Last Updated on 14/11/2020
Design patterns are a collection of abstract solutions to recurrent problems in object-oriented software development. These solutions are presented like templates that can be applied in many situations and programming languages, but with similar structures, providing a design which contributes to system’s flexibility, extensibility, portability and code reuse.
Elements of a Design Pattern
In general, a design pattern has four essential elements:
- Name: a handle we can use to describe a design problem, its solutions and the consequences in a word or two. It gives the possibility to communicate with our colleges and create documentations.
- Problem: describes when to apply the pattern, by explaining the problem and its context. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern.
- Solution: describes the elements of design to solve the problem, their relationships, responsibilities and collaborations. It describes how to arrange these elements to solve the given problem.
- Consequences: describes the results and trade-offs of applying the pattern. The consequences usually consist of space and time trade-offs, and sometimes language and implementation issues, becoming a critical concern for evaluating a design alternative.
Organization of Design Patterns
Design patterns can be divided into three types:
- Creational: abstract the instantiation process. How objects are created, composed and represented become system independent, by hiding its implementation details under the use of inheritance, giving you lot of flexibility and taking away complex object instantiation processes.
- Structural: are concerned with how classes and objects are composed to larger structures. They describe ways to compose objects to realise new functionalities without adding complexity while guaranteeing flexibility, to avoid ending up with “Frankenstein” classes.
- Behavioural: are focused on algorithms and the assignment of responsibilities between objects. They characterise complex control flow that’s difficult to follow at run-time, then shift your focus away from the said flow to let you concentrate just on the way objects communicate to each other.
List of Design Patterns
I’m going to make a compilation of design patterns dividing them by its three types and updating the list below with links. The list is based on GoF (Gang of Four, authors of the book Design Patterns: Elements of Reusable Object-Oriented Software) and another great complementary sources of design patterns content. It starts with the Builder design pattern:
- Chain of Responsability
- Double Dispatch
- Hook Classes
- Hook Method
- Null Object
- Template Method
Any suggestions are welcome!
Hope it helps, cya!