23 design patterns for PHP 2

不言
Release: 2023-03-24 07:22:02
Original
1423 people have browsed it

This article introduces the 23 design patterns 2 of PHP, which has certain reference value. Now I share it with you. Friends in need can refer to it

2. Design Patterns The six principles

1. Open Close Principle

The Open Close Principle means that it is open to expansion and closed to modification. When the program needs to be expanded, the original code cannot be modified to achieve a hot-swappable effect.

So in one sentence, in order to make the program scalable and easy to maintain and upgrade. To achieve such an effect, we need to use interfaces and abstract classes. We will realize this in the specific design later

2. Liskov Substitution Principle LSP

One of the basic principles of object-oriented design. The Liskov Substitution Principle says that wherever a base class can appear, a subclass can definitely appear.

LSP is the cornerstone of inheritance reuse. Only when the derived class can replace the base class and the function of the software unit is not affected, the base class can be truly reused, and the derived class can also be used in the base class. Add new behaviors based on it.
The Richter substitution principle is a supplement to the "open-closed" principle. The key step in realizing the "open-closed" principle is abstraction.

The inheritance relationship between base classes and subclasses is the concrete embodiment of abstraction, so the Liskov substitution principle is a specification for the specific steps to achieve abstraction.

3. Dependence Inversion Principle

This is the basis of the opening and closing principle. The specific content: programming for interfaces relies on abstraction rather than concreteness.

4. Interface Segregation Principle

This principle means: using multiple isolated interfaces is better than using a single interface. It also means reducing the coupling between classes. From this we can see that design patterns are actually the design ideas of a software.

Starting from large-scale software architecture, in order to facilitate upgrades and maintenance, dependencies must be reduced. Reduce coupling

5. Demeter Principle (Demeter Principle)

Why is it called the least known principle, that is to say: an entity should have as few interactions with other entities as possible The interaction makes the system function modules relatively independent

6. Composite Reuse Principle

The principle is to use synthesis and aggregation as much as possible instead of using inheritance.

Related recommendations:

23 design patterns of PHP 1

The above is the detailed content of 23 design patterns for PHP 2. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!