We can endlessly discuss design patterns. Their main purpose is that they help novice and experienced programmers save time during development, minimize the number of errors and, in general, look more competent when talking with colleagues 🙂
Therefore, we are launching a series of articles devoted to patterns. In the first part of the material, we will look into what design patterns are and how they differ from architectural ones.
Other articles of this series:«Creational patterns»,«Structural patterns» and«Behavioral patterns».
WHAT ARE DESIGN PATTERNS?
A complete understanding of patterns appeared in 1994 after the publication of the sensational book “Design Patterns: Elements of Reusable Object-Oriented Software” by the authors who are often referred to as the “Gang of Four”.
In the book, a pattern is understood as a description of the interaction of objects and classes adapted to solve a common design problem in a specific context.
Simply put, design patterns are solutions to common problems in code development. They are also known as design patterns, or object-oriented programming patterns. Unlike ready-made functions or libraries, a pattern is not a specific code, but a general concept for solving a problem, which still needs to be adjusted to the tasks.
Any reason to know patterns?
- Proven solutions. You spend less time using off-the-shelf solutions instead of reinventing the wheel
- Code standardization. Using standard solutions, you make fewer miscalculations when developing since all possible problems have already been found
- General programming vocabulary. Instead of explaining the logic of your code to a colleague for a long time, you name the pattern you want to use and save time for yourself and the others.
WHAT KIND OF DESIGN PATTERNS EXIST
In total, there are 23 classic patterns that were described in the book by the “Gang of Four”. Depending on what tasks patterns solve, they are divided into three types – creational, structural, and behavioral.
Creational patterns are designed to create an instance of an object or a group of related objects. These include:
- Abstract Factory
- Factory Method
Structural ones are mainly related to the composition of objects, with how entities can use each other. These include:
Behavioral associated with the distribution of responsibilities between objects. Their difference from structural patterns is that they describe not only the structure, but also the ways of communication between them. These include:
- Chain of responsibility
- Template method
DESIGN PATTERNS VS. ARCHITECTURAL PATTERNS — WHAT IS THE DIFFERENCE
Beginners may confuse design patterns with architectural ones, as developers usually refer to both as patterns in conversation. Let’s see the differences.
Design patterns provide solutions for customizing and building subsystems at the code level. Usually, their choice is influenced by the programming language, and the developer himself decides which pattern to use.
Architectural patterns are considered at a higher level. They define the architecture of the application, its logic (which components/modules the application will be divided into and how they interact), and help the developer understand how the product works inside. The choice of patterns occurs at the stage of product creation.
You’ve probably heard of many of the architectural patterns already. For example, client-server architecture, event bus, MVC, or interpreter. You can read more about the most popular patterns in this article.
Design patterns are solutions to common problems in code development. Knowing and using them allows you to save time by using ready-made solutions, standardize code and increase the overall programming vocabulary.
The main difference between design patterns and architectural patterns is that the former provide solutions at the code level. Usually, their choice is influenced by the programming language, and only the developer decides which pattern to use.
Architectural patterns define the architecture of the application, set its logic and help the developer understand how the product works inside.
Depending on what tasks design patterns solve, they are divided into three types: creational, structural and behavioral. In the following articles, we will talk in more detail about each type and analyze the 9 most popular patterns that programmers most often use.
MATERIALS FOR ADDITIONAL STUDY
“Design Patterns: Elements of Reusable Object-Oriented Software” byErich Gamma, Richard Helm,Ralph Johnson, andJohn Vlissides, with a foreword byGrady Booch. — that very book by the “Gang of Four”.
Refactoring.guru — Design Patterns and Principles eBook