Introduction to the eight design patterns of PHP

Source: Internet
Author: User
The importance of design patterns in object-oriented objects.
More in-depth understanding of object-oriented thinking, is conducive to the development of highly scalable programs. There is a "closing principle" in the PHP object-oriented: "Software entities should be open to extensions and closed to modifications."     Popular saying: Add new class/interface, etc. come in line, modify not. 1. Factory mode
In simple terms, it is the class that is used to instantiate the corresponding class. For example: PHP may be connected to MySQL, may be connected to SQL Server, or Oracle database, you can dynamically go to the link.
The book <php authoritative programming > (English name for PHP 5 Power programming) also mentions an example of a factory model: Users who are divided into many roles when registering for a user. such as book users, anonymous users, administrator users and so on. Full use can be done using the idea of the factory, the code is easy to maintain, the class that can generate the action for each role.
Details: Click on the Open link
2. Single case mode
Reduces memory overhead, regardless of how many times an instantiation produces only one object.
A single example of PHP, just a single example in the process, not like Java, in the entire memory of the single example.
Details: Click on the Open link
3. Responsibility Chain Mode
When it happens to find the nearest class (the lowest level) to solve, if you can not solve it, go up and look for higher responsibility until the resolution.
Note: There must be a class with the highest responsibility, otherwise there will be a problem.
Details: Click on the Open link
4. Observer mode
Divided into the observer, the observed. The observer is monitored at all times to make corresponding changes in a timely manner.
Details: Click on the Open link
5. Strategy mode
Provides a virtual whole that provides different "parts" (instantiating different object returns) according to different requirements (parameters).
Very similar to the factory model.
Details: Click on the Open link
6. Decorator Mode
A chain from the initial value "decorated" to the final value. Dynamic, and good scalability.
Details: Click on the Open link
7. Adapter Mode
Converts an abstraction to the desired format for another requirement.
In the life also everywhere has the appearance of the adapter, for example transforms the head, is lets two kinds of different specification suitable collocation together.
Details: Click on the Open link
8, Bridging mode
An abstraction produces a variety of concrete implementations, and the mere inheritance of subclasses can explode with subclasses (too many subclasses), and the system needs dynamic coupling between them.
Details: Click on the Open link


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.