Home > Common Problem > What are the six principles of design patterns?

What are the six principles of design patterns?

coldplay.xixi
Release: 2023-01-13 00:31:59
Original
41331 people have browsed it

The six principles of design pattern: 1. Unity principle; 2. Richter substitution principle; 3. Dependency inversion principle; 4. Interface isolation principle; 5. Dimit principle; 6. Opening and closing principle.

What are the six principles of design patterns?

#The operating environment of this article: Windows 7 system, Dell G3 computer.

Six principles of design pattern:

1. Single Responsibility Principle: A class or a method is only responsible for one responsibility , try to ensure that there is only one behavioral reason for the class that causes changes;

a. Split the business object (BO business object) and business logic (BL business logic);

2. Liskov substitution principle(LSP liskov substitution principle): Subclasses can extend the functions of the parent class, but cannot change the functions of the original parent class; (The essence is actually the polymorphism of c)

 (Purpose : Enhance the robustness of the program) In actual projects, each subclass corresponds to a different business meaning, so the parent class is used as a parameter to pass different subclasses to complete different business logic.

3. Dependency inversion principle (dependence inversion principle): interface-oriented programming; (implementing application scenarios through interfaces as parameters)

Abstraction is an interface or abstract class, details It is the implementation class

Meaning:

The upper module should not depend on the lower module, both should rely on its abstraction;

Abstraction should not rely on details, and details should rely on abstraction;

The popular point is to use abstract classes or interfaces as much as possible for variables or parameters;

[Interfaces are responsible for defining public properties and methods, and declaring dependencies with other objects, and abstract classes are responsible for public structures. Partial implementation, implementation class accurately implements business logic】

4. Interface segregation principle(interface segregation principle): Establish a single interface; (Extended to a class is also an interface, everything is Interface)

Definition:

a. The client should not rely on interfaces it does not need;

b. Dependencies between classes should be established on the smallest interface;

Simple understanding: A complex interface is split into multiple simple interfaces according to the business; (for some business splits, look at the adapter application)

[The smaller the design granularity of the interface, the smaller the interface design granularity. , the more flexible the system, but at the same time the flexibility increases the structural complexity, the development difficulty will also become greater, and the maintainability will decrease]


5. Law of Demeter LOD): Least known principle, try to reduce the coupling between classes; An object should have the least knowledge about other objects

6. Opening and closing principle

(open closed principle): Use abstraction to build architecture and implement expansion principles;

Related free learning recommendations:

php programming (video)

The above is the detailed content of What are the six principles of design patterns?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template