PHP legacy system based on namespace refactoring experience php namespace case php namespace Auto load php namespace us

Source: Internet
Author: User
Namespaces are actually just a form, and the ultimate goal is to refactor the code, but it's impossible to do this in a single pass.

At first, a pseudo proposition was given: thinkphp-based refactoring (not why). After a period of practice, it is found that this is a wrong way of thinking, in which the pits encountered in this slightly not table.

First, don't try to rewrite the whole namespace based on namespaces, but should be local.

The result of the final thinking is that the model layer is based on the transformation of the namespace, so that the model layer resources in the system can be reused under the new framework. Because the model layer in theory only deals with data, the least coupling.

But the transformation process also found some problems, the model layer coupled with business logic, even with the session, cache and other system environment, not purely DB operations, but contains a lot of business code, which means that this part of the code after the initial transformation is completed, it is not reusable in the new framework.

These problems also indirectly prove the correctness of some basic programming ideas: The essence of OOP is code reuse, the direct effect of the PSR Series specification to improve code reusability, the effect of code layering rationality on the maintainability of code, and the extreme negative effect of global variables on code reusability.

What is progressive refactoring?

The basic principle of progressive refactoring is compatibility, not overturning, as long as things become pushed to the back, it is not refactoring, is simply rewriting. In the entrepreneurial small team, pushed to rewrite, are u kidding me?

Compatibility is the starting point and process of refactoring, reuse is the result, new functionality can be developed based on a new framework, but you can reuse existing functional code, so this is a process.

The above describes the old PHP system based on the namespace refactoring experience, including the namespace, PHP content, I hope to be interested in PHP tutorial friends helpful.

  • 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.