This is the 23rd day of my participation in Gwen Challenge

Author: Thirty-three days

Blog: www.zhouhuibo.club

Introduction to Design Patterns

Design patterns represent best practices and are generally adopted by experienced object-oriented software developers. Design pattern is a solution to the common problems faced by software developers during software development. These solutions have been developed by numerous software developers over a long period of trial and error.

A design pattern is a set of repeated, well-known, catalogued code design lessons. Design patterns are used to reuse code, make it easier for others to understand, and ensure code reliability. There is no doubt that design patterns are a win-win for yourself, others and systems. Design patterns make coding truly engineering. Design patterns are the cornerstones of software engineering, like the bricks and stones of a mansion. The rational application of design patterns in projects can perfectly solve many problems. Each pattern has its corresponding principle in reality, and each pattern describes a recurring problem around us, as well as the core solution of the problem, which is also the reason why design patterns can be widely used.

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 a particular situation. For example, the singleton design pattern means using a single object so that all developers familiar with the singleton design pattern can use a single object and tell each other that the program is using the singleton pattern.

Best practices

Design patterns have evolved over a long period of time, and they provide the best solutions to common problems faced in software development. Learning these patterns helps inexperienced developers learn software design in an easy and quick way

Types of design patterns

There are 23 Design Patterns in all, according to the reference book Design Patterns – Elements of Reusable Object-oriented Software. These Patterns fall into three broad categories: Creational Patterns, Structural Patterns, and Behavioral Patterns.

Create a type (5)

These design patterns provide a way to hide the creation logic while creating objects, rather than instantiating objects directly using the new operator. This gives the program more flexibility in deciding which objects to create for a given instance.

  • Factory Method Pattern
  • Abstract Factory Pattern
  • Singleton
  • Builder Mode
  • Prototype mode

Structured (7)

These design patterns focus on combinations of classes and objects. The concept of inheritance is used to combine interfaces and define how composite objects acquire new functionality.

  • Adapter mode (Adapter)
  • Bridge mode (Bridge)
  • Composite mode
  • Decorator pattern
  • Facade Pattern
  • Flyweight Mode
  • Proxy mode

Behavior type (11)

These design patterns are particularly concerned with communication between objects.

  • Chain of Responsibility model
  • Command mode
  • Interpreter mode
  • Iterator pattern (Iterator)
  • Mediator Mode
  • Memento Mode
  • Observer Model
  • State mode
  • Strategy Pattern
  • Template pattern (Template)
  • Visitor Pattern

Common patterns

  • Abstract Factory Pattern
  • Adapter mode (Adapter)
  • Composite mode
  • Decorator pattern
  • Factory Method Pattern
  • Observer Model
  • Strategy Pattern
  • Template pattern (Template)

Six principles of design patterns

1. Open Close Principle

The open closed principle means: open for extensions, closed for modifications. When the program needs to be extended, you cannot modify the original code to achieve a hot plug effect. In short, to make the program extensible, easy to maintain and upgrade. To achieve this, we need to use interfaces and abstract classes, which will be discussed later in the concrete design.

2. Liskov Substitution Principle

Richter’s substitution principle is one of the basic principles of object-oriented design. Richter’s rule of substitution says that wherever a base class can appear, a subclass must appear. LSP is the cornerstone of inheritance reuse. The base class can be reused only when the derived class can replace the base class and the function of the software unit is not affected. The derived class can also add new behaviors on the base class. Richter’s substitution principle is a complement to the open – close principle. Abstract is the key step to realize the open and close principle, and the inheritance relationship between base class and subclass is the concrete realization of abstraction, so the Richter substitution principle is the specification of the concrete steps to realize abstraction.

3, Dependence Inversion Principle

This principle is the basis of the open closed principle, the concrete content: programming for interfaces that rely on abstraction rather than on concrete.

4. Interface Segregation Principle

This principle means that it is better to use multiple isolated interfaces than a single one. It also has another meaning: reducing coupling between classes. Thus, in fact, design mode is a software design idea that starts from large-scale software architecture and is easy to upgrade and maintain. It emphasizes reducing dependence and coupling.

5. Demeter Principle, also known as the Least Known Principle

The least known principle means that an entity should interact with other entities as little as possible, so that the functional modules of the system are relatively independent.

Composite Reuse Principle

The principle of composite reuse is to use composition/aggregation rather than inheritance whenever possible.

END

Welcome to pay attention to the public number programmer tool set 👍👍 is committed to sharing excellent open source projects, learning resources, common tools

Reply keyword “attention package”, send you a complete map of programmer skills.

Reply keyword “wX” add personal wechat, hook up with the author, welcome to chat ^-^.