Designing PHP projects with encapsulation classes: class encapsulation in PHP projects

Source: Internet
Author: User
Coding is not difficult for qualified PHP programmers (it may only take a long time). Therefore, this stage of system analysis and design is particularly important. However, this article is not intended to discuss the topics related to demand analysis and commercial logic, but to discuss the system design. Coding is not difficult for qualified PHP programmers (it may only take a long time). Therefore, this stage of system analysis and design is particularly important. However, this article is not intended to discuss the topics related to demand analysis and commercial logic, but to discuss the system design.

Coding is not difficult for qualified PHP programmers (it may only take a long time). Therefore, this stage of system analysis and design is particularly important. A system analyst for a PHP project faces two challenges:

  1. Restrictions on the PHP language itself.
    This is particularly significant in the object-oriented design of complex systems. Although PHP's object-oriented feature has been improved in the existing version, it is not sound enough to serve as the implementation language of object-oriented design, in the new PHP version supported by Zend Engine 2.0 that will be released soon, object-oriented features will not be the same as the popular Java or C ++ (For more information, see another article I posted on the developerWorks Chinese website ). However, if we adopt a completely process-oriented approach (specifically for Web pages), we can imagine that the design of the entire system will be very complicated, and the resulting complexity of coding and maintenance difficulties will be even more difficult to cope.
  2. Serious lack of existing information.
    This is a well-known phenomenon, that is, insufficient system design materials for Web Projects. among these limited materials, PHP design materials are scarce. If the company or myself do not have any technical accumulation, the system analyst can only find a way in the dark (two worse cases, one is to copy the design of other projects such as Java or C ++, the second is to think that the project is simple and irresponsible ).


In this case, how can we properly analyze and design the PHP system? The initial idea should clarify the types of tasks undertaken by the project:

  1. Projects that involve the business logic of a large number of customers themselves or their industries, including office systems, order systems, and other business systems.
  2. Simple website projects include projects that require high access traffic or fast response, such as brand websites or activity websites, and other websites.
  3. Comprehensive website project. It usually contains multiple relatively independent subsystems, such as the news subsystem, Forum subsystem, and product display subsystem.


The original intention of PHP is to solve the urgent needs of the latter two projects. the language itself has well transformed these projects. Many PHP developers have more or less experience in these projects, and most examples in related books are centered around this. Relatively speaking, there is not much information in the first system, and the content of various publications is rarely mentioned. Therefore, this article describes the first type of project in detail (about MVC mode and class encapsulation), and also mentions the second type of project (about hacker code) and the third project design method. Of course, not classified projects can only be described in this document, and system analysts need to weigh various factors to choose from.

How do I separate user interfaces from background operations? How can we avoid obfuscation of business logic in general process control? As a rigorous commercial project, many similar problems need to be considered. For such projects undertaken by PHP, implementing the Model-View-Controller (MVC) pattern design is a very good method.

Theoretical description
Here I don't want to explain more about the MVC model itself-simply put, literally, by dividing the system design into three logical parts: Model/logic, View/interface, and Controller control/process, a good project effect is achieved, this facilitates the work of various developers and reduces maintenance costs in the future. (If you are familiar with the Model 2 mode developed by JSP, you can find that it is also a good embodiment of the MVC mode .) As far as practical project development is concerned, there are many major problems, including the staggered and conflicting work of web designers and program developers, and the unavailability and maintenance of business logic embedded pages. The introduction of the MVC model can provide a clear direction for the overall design of the system and provide good guidance for the division of labor among development teams.

Since the overall structure of the system is logically divided into three parts according to the MVC model, there are also developers for each part of the team.

Developer role Related system logic Responsibilities
Web designer View/interface Design webpage templates for all user interfaces.
Control process developers Controller control/process Compile all PHP pages in the system flow.
Business logic developers Model/logic The classes (methods) specified in the development system design ).

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.