Designing PHP Project rationally with encapsulation class--on encapsulation of class in PHP project

Source: Internet
Author: User
The code is as follows Copy Code



Coding is not difficult for qualified PHP programmers (perhaps just a matter of time), so the system analysis and design phase becomes particularly important. However, this article does not intend to discuss and demand analysis, access to business logic related topics, but to the system design aspects of the discussion.

Face problems
Coding is not difficult for qualified PHP programmers (perhaps just a matter of time), so the system analysis and design phase becomes particularly important. For a system analyst who acts as a PHP project, there are two challenges:

    1. Limitations of the PHP language itself.
      This is particularly noticeable in the object-oriented design of complex systems. The object-oriented nature of PHP, although improved in the existing version, is not robust enough to serve as an object-oriented design implementation language; Even if the vision is long, in the upcoming release of the Zend Engine 2.0 support of the new PHP, Object-oriented features will not be as popular as Java or C + + (see my other article on the Developerworks China Web site for this content). But if you adopt a completely process-oriented approach to Web pages, you can imagine that the design of the entire system is complex, and the resulting coding complexity and maintenance difficulties are more difficult to cope with.
    2. A serious lack of available information.
      This is a well-known phenomenon that the system design data for Web projects is insufficient, and in these limited data, the design information about PHP is very scarce. If the company or I do not have the relevant technology accumulation, system analysts can only find ways in the dark (worse two cases, one is to copy other projects such as Java or C + + design, the second is to think that the project simple and irresponsible hastily).

Recognizing the system facing
So, what is the best way to handle the analysis and design of PHP systems? The original idea should be to distinguish between the types of project commitment tasks:

    1. Projects that involve a large number of customers themselves or the business logic of the customer's industry, including office systems, order systems, and other business systems.
    2. Simple Web site projects, including projects that require high levels of traffic or require quick response, such as branded or active sites, and other sites.
    3. Comprehensive website Project. Usually contains a number of relatively independent subsystems such as news subsystem, forum subsystem, product display subsystem and so on.

PHP is designed to address the urgent needs of the latter two projects, the language itself for these projects have been a good transformation. Many PHP developers have more or less experience with these projects, and most of the examples in related books revolve around this. Relative to the first system all the information is not much, the various publications on its content is rarely mentioned. So in this article, the first type of project is described in detail (about the MVC pattern and the class encapsulation), along with a reference to the second project (about hacking code) and the design method of the third project. Of course, not all of these items are categorized in the way described in this article, and the system analyst needs to weigh the various factors to choose.

Programme I: Involving a large number of business logic projects
How do I detach the user interface and background operations? How do you avoid confusing business logic with general process control? As a rigorous commercial project, many similar issues need to be considered. Implementing the design of the Model-view-controller (MVC) pattern is a great way to implement this type of project that is played by PHP.

Theoretical description
here I don't want to explain the MVC pattern itself--simply literally and in application, by dividing the design of the system into model/logic, view views/interfaces, controller control/flow three logical parts to achieve good project results, In order to facilitate the work of the various parts of the developers and reduce future maintenance costs. (If you are familiar with JSP development Model 2 mode, you can find that it is also a good embodiment of the MVC pattern.) As far as realistic project development is concerned, the major problems that exist include the staggered and conflicting work of web designers and developers, and the fact that business logic embedded pages are not reusable and difficult to maintain, and so on. The introduction of MVC pattern can be a clear direction for the overall design of the system, which is also a good guide for the development team's division of labor.

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

Developer role Related system logic Duty
Web Design Staff View View/interface
<

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.