TOP1. Overview of software design patterns

                                       Overview of software design patterns

         The background of software design patterns

Concept and meaning of software design pattern

1. The concept of software design patterns

2. The significance of learning design patterns

Basic elements of software design patterns

1. Mode name

2. Problem

3. Solution

4. Effect


The background of software design patterns


The term "design pattern" did not initially appear in software design, but was used in the design of architecture.

In 1977, Christopher Alexander, a famous American architect and director of the Environmental Structure Center at the University of California, Berkeley, wrote in his book A Pattern Language: Towns Building Construction (A Pattern Language: Towns Building Construction) Describes some common architectural design problems, and proposes 253 basic patterns for designing towns, neighborhoods, houses, gardens and rooms.

In 1979, his other classic work "The Timeless Way of Building" (The Timeless Way of Building) further strengthened the idea of ​​design mode and pointed out the direction for later architectural design.

In 1987, Kent Beck and Ward Cunningham first applied Christopher Alexander’s pattern to the generation of graphical user interfaces in Smalltalk, but they did not cause any problems in the software industry. attention.

It was not until 1990 that the software engineering community began to discuss the topic of design patterns, and later held several seminars on design patterns.

In 1995, four authors including ErichGamma, Richard Helm, Ralph Johnson, John Vlissides, etc. Co-published the book "Design Patterns: Elements of Reusable Object-Oriented Software" (Design Patterns: Elements of Reusable Object-Oriented Software). In this tutorial, 23 design patterns are included, which is a milestone event in the field of design patterns. , Leading to a breakthrough in software design patterns. These four authors are also known as their "Gang of Four" (GoF) anonymously in the field of software development.

Until today, the narrow design pattern is the 23 classic design patterns introduced in this tutorial.

The term "design pattern" did not initially appear in software design, but was used in the design of architecture.

Concept and meaning of software design pattern


There are many definitions of software design patterns, some are explained from the characteristics of the pattern, and some are explained from the role of the pattern. The definition given in this tutorial is recognized by most scholars, and it is explained from the following two aspects.

1. The concept of software design patterns

Software Design Pattern (Software Design Pattern), also known as design pattern, is a set of code design experience that has been used repeatedly and is known to most people. It describes some recurring problems in the software design process and the solutions to the problems. In other words, it is a series of routines to solve specific problems, is a summary of the code design experience of the predecessors, has a certain generality, and can be used repeatedly. Its purpose is to improve code reusability, code readability and code reliability.

2. The significance of learning design patterns

The essence of design patterns is the practical application of object-oriented design principles, which is a full understanding of the encapsulation, inheritance, and polymorphism of classes, as well as the association and composition relationships of classes. The correct use of design patterns has the following advantages.

  • Can improve the programmer's thinking ability, programming ability and design ability.
  • The program design is more standardized, the code preparation is more engineering, and the software development efficiency is greatly improved, thereby shortening the software development cycle.
  • The designed code is highly reusable, readable, reliable, flexible, and maintainable.


Of course, the software design pattern is just a guide. In the specific software development, it must be properly selected according to the characteristics and requirements of the designed application system. For simple program development, it is easier to write a simple algorithm than to introduce a certain design pattern. But for the development of large projects or framework design, it is obviously better to use design patterns to organize the code.

Basic elements of software design patterns


Software design patterns make it easier and more convenient for people to reuse successful designs and architectures. It usually contains the following basic elements: pattern name, alias, motivation, problem, solution, effect, structure, pattern role, cooperative relationship, Implementation methods, applicability, known applications, routines, pattern extensions and related patterns, among which the most critical elements include the following 4 main parts.

1. Mode name

Each mode has its own name, which is usually described by one or two words, which can be named according to the mode's problems, characteristics, solutions, functions and effects. The pattern name (PatternName) helps us understand and remember the pattern, and it is also convenient for us to discuss our own design.

2. Problem

Problem (Problem) describes the application environment of the mode, that is, when to use the mode. It explains the causes and consequences of design problems and problems, and a series of prerequisites that must be met.

3. Solution

The solution to the model problem includes the components of the design, the relationship between them, and their respective responsibilities and collaboration methods. Because the pattern is like a template, it can be applied to many different occasions, so the solution does not describe a specific and specific design or implementation, but provides an abstract description of the design problem and how to use a combination of elements with general meaning (class Or a combination of objects) to solve this problem.

4. Effect

Describes the application effects of the model and the issues that should be weighed when using the model, namely the advantages and disadvantages of the model. It is mainly to measure time and space, as well as the impact of this mode on the flexibility, scalability, and portability of the system, and also consider its implementation. Explicitly listing these effects (Consequence) is of great help to understanding and evaluating these patterns.

                                                                                                                                                                    23 design patterns of GOF>

Guess you like

Origin blog.csdn.net/m0_38023584/article/details/106340290