Writing in the front

  • Take notes on learning design patterns
  • Improve the flexible use of design patterns

Learning to address

www.bilibili.com/video/BV1G4…

www.bilibili.com/video/BV1Np…

Refer to the article

C.biancheng.net/view/1317.h…

Program source codeGitee.com/zhuang-kang…

1. Overview of design patterns

1.1 Background of software design pattern

“Design patterns” did not originally appear in software design, but were used in architectural design.

In 1977, Christopher Alexander, a famous American architect and director of the Center for Environmental Structures at the University of California, Berkeley, wrote in his book Architectural Pattern Language: “Towns, Buildings, Structures” describes some common architectural design problems and proposes 253 basic patterns for designing towns, neighborhoods, houses, gardens, and rooms.

The topic of design patterns began to be discussed in the software engineering community in 1990, and there have been many conferences on design patterns since then. It was not until 1995 that ErichGamma, Richard Helm, Ralph Johnson, John Vlissides, and other four authors collaborated on the book design patterns: The Foundation of Reusable Object-oriented Software, in which 23 design patterns are included, is a landmark event in the field of design patterns, leading to breakthroughs in software design patterns. The Four authors are also known in the software development world as their Gang of Four (GoF).

1.2 The concept of software design patterns

Software Design Pattern, also known as Design Pattern, is a set of repeatedly used, most people know, after classification and cataloging, code Design experience summary. It describes some recurring problems in the software design process, and the solutions to this problem. That is to say, it is a series of routines to solve a specific problem. It is a summary of the code design experience of predecessors. It has a certain universality and can be used repeatedly.

1.3 The necessity 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 the encapsulation, inheritance and polymorphism of classes, as well as the association and combination of classes.

Using design patterns correctly has the following advantages.

  • Can improve the programmer’s thinking ability, programming ability and design ability.
  • Make the program design more standardized, code preparation more engineering, so that the software development efficiency is greatly improved, thus shortening the software development cycle.
  • So that the design of the code can be reused, readability, high reliability, good flexibility, maintainability.

1.4 Classification of design patterns

  • Creation pattern

    It describes how to create objects. Its main feature is to “separate the creation and use of objects”. The GoF book provides five creation patterns: singletons, prototypes, factory methods, Abstract factories, and Builders.

  • Structural mode

    The GoF book describes how a class or object can be arranged into a larger structure. There are seven structural patterns in the GoF book: broker, adapter, bridge, decorator, facade, share, and composition.

  • Behavioral pattern

    Describes how classes or objects work together to accomplish tasks that a single object cannot accomplish alone, and how responsibilities are assigned. The GoF book provides 11 behavioral patterns of template methods, policies, commands, chains of responsibility, states, observers, mediators, iterators, visitors, memos, interpreters, etc. Write in the last

    • If my article is useful to you, please give me a click 👍, thank you 😊!
    • If you have any questions, please point them out in the comments section! 💪