Php design patterns and coupling and Polymorphism
What is the design model:
The design pattern is a template that teaches you how to organize your code using authentic and reliable design.
All design patterns have some common features: a name, a problem statement, and a solution ).
1. the logo of a design pattern is important, because it allows other programmers to understand the purpose of your code immediately without having to study it too deeply (at least the programmer will be familiar with this pattern through this identification ).
2. The problem description is used to describe the application fields of this model.
3. The solution describes the execution of this model. The discussion of a good design model should cover the advantages and disadvantages of using this model.
For example, the color, style, and size of a shirt you buy from a store is determined by the designer and manufacturer, but it meets your needs. However, if there are no clothes in the store that suit you, you can create your own shirt (design its shape, select the fabric, and then make a tailor together ). But if you are not a tailor, you may find it easy to find a proper pattern and then design your shirt according to the pattern. With a model, you can get a well-designed shirt in less time.
Php has 23 traditional design models,
Interpreter (Interpreter mode), Factory (Factory mode), Facade (appearance mode), Decorator (decoration mode), Builder Mode)
Adapter (Adapter mode), Template (Template mode), Command (Command chain mode), Singleton (Singleton mode), Observer (Observer Mode)
Strategy, Visitor, Memento, Prototype, and Mediator)
FlyWeight, Chain Of Responsibility, Bridge, Proxy, and State)
Composite, Interator, DAO, and Delegation)
There are five common php design patterns.
1. Factory Mode 2. Singleton mode (Singleton mode) 3. Observer Mode 4. command chain mode 5. Policy Mode
What is coupling:
Coupling is a measurement of the degree of association between modules. The coupling strength depends on the complexity of the interface between modules, the method of calling the module, and the amount of data transmitted through the interface. The Coupling Degree between modules refers to the dependency between modules, including the control relationship, call relationship, and data transmission relationship. The more inter-module connections, the stronger the coupling, and the poorer the independence. In software design, coupling and cohesion are commonly used as the criteria for measuring the degree of module independence. One criterion for block division is high cohesion and low coupling.
What is polymorphism:
"For object-oriented programming languages, multi-type is the third most basic feature (the first two are data abstraction and inheritance ."
Polymorphism separates interfaces from the specific implementation details from another perspective, that is, the separation of the two modules "what" and "how to do" is realized. With the concept of polymorphism, code organization and readability can be improved. In addition, you can create programs that are easy to expand. During project creation or when new features need to be added, they can easily "grow ".