PHP Design Patterns and coupling and polymorphism

Source: Internet
Author: User
Tags object interface new features
What is a design pattern:

Design patterns are a template that teaches you how to organize your code using a truly reliable design.

All design patterns have some common features: an identifier (a name), a problem statement (a problem statement), and a solution (a solution).

1. The identification of a design pattern is important because it allows other programmers to immediately understand the purpose of your code (at least through this identification programmer will be familiar with this pattern) without having to study too deeply.

2, the problem description is used to illustrate the application of this model of the field.

3, the solution describes the implementation of this model. The discussion of a good design pattern should cover the advantages and disadvantages of using this model.

For example, a shirt you buy from a store is a code base whose color, style and size are determined by the designer and manufacturer, but it meets your needs. However, if there are no clothes for you in the store, you can create your own shirt (design its shape, choose the fabric, then tailor it together). But if you are not a tailor, you may find it easy to find a suitable model and then follow the pattern to design your own shirt. Using a model, you can get a expertly designed shirt in less time.

PHP has a total of 23 traditional design patterns,

Interpreter (interpreter mode), Factory (Factory mode), façade (appearance mode), decorator (decorative mode), Builder (builder mode)

Adapter (Adapter mode), Template (template mode), command (order chain mode), Singleton (single case mode), OBSERVER (Observer mode)

Strategy (Policy mode), Visitor (visitor mode), Memento (Memo mode), Prototype (prototype mode), mediator (intermediary mode)

FlyWeight, Chain of responsibility (responsibility chain mode), bridge (bridging mode), proxy (proxy mode), state (status mode)

Composite (combination mode), Interator (iterator mode), DAO (data Access object mode), delegation (delegate mode)

There are five common types of PHP design Patterns

1. Factory mode 2. Single case mode (single element mode) 3. Observer Mode 4. Command chain mode 5. Policy mode

What is coupling:

Coupling (coupling), also called coupling degree, is a measure of the degree of association between modules. The coupling depends on the complexity of the interface between the modules, the way the module is invoked, and how much data is transmitted through the interface. The coupling degree between modules refers to the dependencies between modules, including control relations, call relationships and data transfer relationships. The more connections between modules, the stronger the coupling, and the worse the independence of the module. In software design, the degree of independence of the module is usually measured by the coupling degree and the cohesion degree. One criterion for dividing the blocks is cohesion well-structured classes coupling

What is the polymorphism of:

For object-oriented programming languages, polymorphism is the third most basic feature (the first two are data abstraction and inheritance.) ”

"Polymorphism" separates the interface from the concrete implementation details from another angle, i.e., the separation of "what is" and "How to Do" two modules. Using the concept of polymorphism, the organization of code and readability can be improved. In addition, you can create "easy to extend" programs. They can be easily "grown" both during project creation and when new features need to be added.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.