search
HomeCommon ProblemWhat are the six principles of design patterns?

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor