Design Patterns, Definitions, History, and Categories
Design patterns are solutions to common software design problems. Knowing these patterns distinguishes a professional programmer from an ordinary one. No matter what programming language you code in, learning and using these templates, you can go a long way in designing software. So do not miss this article.
What are Design patterns?
Over time, programmers have encountered various problems in software development. Many of these difficulties were independent of programming languages and similar to each other.
Various solutions were presented to solve these problems, the best of which is called Design patterns. In other words, sets of the best solutions to common problems in the software programming process are called design patterns.
Experienced programmers develop design patterns to solve common problems in object-oriented programming.
Design patterns are not part of software architectures and only provide the correct way of object-oriented coding. These patterns only enter the realm of object-oriented coding and are independent of programming languages.
History of design patterns
Design patterns were first proposed by Christopher Alexander, who referred to them as solutions to problems that commonly occur in the programming process.
In 1994, a group called the ‘Gang of Four,’ consisting of Eric Gamma, Richard Helm, Ralph Johnson, and the Wilsides Cup, categorized design patterns in terms of application. The Gang of Four, or GOF for short, published these patterns in a book called ‘Design patterns.’ This book divides 23 of the design patterns into three general categories and introduces and teaches them. Gamma and his colleagues have considered a specific structure to introduce each pattern.
They have refused to visually introduce design patterns as they believed this introduction required a new and specific structure. The main components of this structure are:
- Name and classification: states the name of the pattern and a short description of it.
- Purpose: In this section, a brief description of the pattern intention is provided.
- Another name: If the pattern has another name, it is mentioned in this section.
- Solution: This section deals with a scenario in which a design pattern is used and how to utilize classes and objects to solve the problem.
- Application: This part describes the conditions under which the model will be used.
- Structure: Here, the main structure of design patterns is displayed using UML.
- Classes and object usage: The role of classes or objects used in the pattern is mentioned in this section.
- Collaboration: How Classes and objects collaborate in the pattern design
- Implementation: Steps of the design implementation
- Sample code: Includes examples in the form of different programming languages.
- Practical examples: Useful examples of the design pattern.
- Relationship with other design patterns: In this section, parts of the design pattern related to other patterns are examined.
Types of design patterns in software engineering
Software engineering design patterns are divided into the following three categories according to their applications and purposes:
- Creational Design patterns
- Structural Design patterns
- Behavioral Design patterns
Creational Design patterns
Creational Design patterns can solve problems related to making objects in the software. The most common of these patterns are as follow:
- Factory Method
- Abstract Factory
- Object Pool
Structural Design patterns
Structural design patterns are a set of solutions that help programmers solve software scalability problems. These pattern designs are used to manage the relationship between classes and objects. Some examples are here:
Behavioral Design patterns
Behavioral design patterns are a set of coding strategies related to the interaction and communication of objects. These design patterns are:
- chain of responsibility
- Template Method