1. Overview of software design patterns

This article introduces the concepts and characteristics of software design patterns as a whole, the basic elements of software design patterns, and an introduction to GoF's 23 design patterns.

The background of software design patterns

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

In 1977, Christopher Alexander, a famous American architect and director of the Environmental Structure Center of 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 models 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 of thinking to the generation of graphical user interfaces in Smalltalk, but they did not cause any problems in the software industry. attention.

It wasn't until 1990 that the software engineering community began to discuss the topic of design patterns, and then several seminars on design patterns were held.

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.
Insert picture description here

Until today, the narrow design pattern is the 23 classic design patterns introduced in this series of articles.

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 repeatedly used, most people know, classified cataloging, code design experience summary. 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 pattern is the practical application of object-oriented design principles, and it is a full understanding of class encapsulation, inheritance and polymorphism, as well as class association and composition relations. 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, the software development efficiency is greatly improved, and the software development cycle is shortened.
Make the designed code high reusability, strong readability, high reliability, good flexibility and strong maintainability.

Of course, the software design pattern is just a guide. In the specific software development, it must be appropriately selected according to the characteristics and requirements of the designed application system. For simple program development, it may be 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, partnership, 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. It 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) 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 (Solution) includes the components of the design, the relationship between them, and their respective responsibilities and collaboration methods. Because a 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 effect of the mode and the issues that should be weighed when using the mode, that is, the advantages and disadvantages of the mode. 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 issues. Explicitly listing these effects (Consequence) is of great help in understanding and evaluating these patterns.

Guess you like

Origin blog.csdn.net/m0_46864744/article/details/112798585