
1. Introduction to design patterns
First of all, let’s understand what design patterns are:
Design patterns It is a summary of a set of reliable code design experiences that have been used repeatedly, are easily understood by others, and are reliable.
Design patterns are not a patent of Java. We can also use 23 design patterns well in PHP using object-oriented methods.
So what is the relationship between the architecture, framework and design patterns we often talk about?
Architecture is a set of system structures and the overall solution for the project; the framework is semi-finished software that can be reused and is the specific program code. Architecture generally involves what kind of framework to use to speed up and optimize the solution of certain problems, and good framework codes use many design patterns reasonably.
Related recommendations: "ThinkPHP Tutorial"
2. Refining several principles of design patterns:
(1) Open-Closed Principle: Modules should be open for extension but closed for modification.
(2) Liskov substitution principle: If the parent class is called, then it can be run if it is replaced by a subclass.
(3) Dependency inversion principle: abstraction does not depend on details, interface-oriented programming, and passed parameters try to reference high-level classes.
(4) Interface isolation principle: Each interface is only responsible for one role.
(5) Principle of composition/aggregation reuse: Use composition/aggregation as much as possible and do not abuse inheritance.
3. What is the function of design pattern?
Design patterns can solve the problem of replacing messy code and form a good code style. The code is easy to read and engineers can easily understand when adding new functions without modifying the interface. It has strong scalability
Stability It has good performance, and generally there will be no unknown problems that cannot be solved by design patterns:
(1) Design patterns are templates used to organize your code, rather than libraries that are directly called;
(2) Design Patterns are not the most efficient, but code readability and maintainability are more important;
(3) Don’t blindly pursue and apply design patterns, think more about it when refactoring.
4. Design Pattern Classification
1. Creation Pattern:
Singleton Pattern, Factory Pattern (Simple Factory, Factory Method, Abstract Factory ), creator mode, prototype mode.
2. Structural mode:
Adapter mode, bridge mode, decoration mode, combination mode, appearance mode, flyweight mode, proxy mode.
3. Behavioral patterns:
Template method pattern, command pattern, iterator pattern, observer pattern, mediator pattern, memo pattern, interpreter pattern, state pattern, strategy pattern, Chain of responsibility model, visitor model.
The above is the detailed content of What design patterns does thinkphp5 use?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment





