Introduction to design patterns
Design patterns represent best practices and are typically used by experienced object-oriented software developers. Design patterns are solutions to common problems faced by software developers during the software development process. These solutions are the result of trial and error by numerous software developers over a long period of time.
A design pattern is a set of code design experiences that are repeatedly used, known to most people, classified and cataloged. The purpose of using design patterns is to reuse code, make the code easier to understand by others, and ensure code reliability. There is no doubt that design patterns are win-win for ourselves, others, and the system. Design patterns make code compilation truly engineering. Design patterns are the cornerstone of software engineering, just like the bricks and stones of a building. Reasonable use of design patterns in projects can perfectly solve many problems. Each pattern has corresponding principles in reality to correspond to it. Each pattern describes a problem that keeps recurring around us, and the solution to the problem. Core solution, which is why design patterns can be widely used.
What is GOF (Gang of Four)?
In 1994, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides co-authored a book called Design Patterns - Elements of Reusable Object-Oriented Software (Chinese translation: Design Patterns - Reusable Object-Oriented Software Elements) book, which first mentioned the concept of design patterns in software development.
The four authors are collectively known as GOF (Gang of Four, spelled out in full Gang of Four). The design patterns they proposed are mainly based on the following object-oriented design principles.
Programm to the interface rather than to the implementation.
Prefer object composition to inheritance.
The use of design patterns
There are two main uses of design patterns in software development.
A common platform for developers
Design patterns provide a standard terminology system that is specific to specific scenarios. For example, the singleton design pattern means using a single object so that all developers who are familiar with the singleton design pattern can use the single object and can tell each other that the program uses the singleton pattern.
Best Practices
Design patterns have been developed over a long period of time and they provide the best solutions to common problems faced during software development. Learning these patterns helps less experienced developers learn software design in a quick and easy way.
Types of design patterns
According to the reference book of design patternsDesign Patterns - Elements of Reusable Object-Oriented Software (Chinese translation: Design Patterns - Reusable Object-Oriented Software Elements ) mentioned in, there are a total of 23 design patterns. These patterns can be divided into three major categories: Creational Patterns, Structural Patterns, and Behavioral Patterns. Of course, we'll also discuss another category of design patterns: J2EE design patterns.
Serial Number | Mode & Description | includes |
---|---|---|
1 | Creational Patterns These design patterns provide a way to hide the creation logic while creating an object, rather than instantiating the object directly using new operators. This allows the program to be more flexible in determining which objects need to be created for a given instance. |
|
2 | Structural Patterns These design patterns focus on the combination of classes and objects. The concept of inheritance is used to compose interfaces and define the way in which composed objects acquire new functionality. |
|
Behavioral PatternThese design patterns pay special attention to the relationship between objects Communication. |
| |
J2EE Patterns | These design patterns focus specifically on the presentation layer. These modes are certified by Sun Java Center. |
|