PHP old system reconstruction experience based on namespace php namespace case php namespace automatic loading php namespace us

WBOY
Release: 2016-07-29 08:52:31
Original
1227 people have browsed it

Namespace is actually just a form. The ultimate goal is to refactor the code, but this process is impossible to do overnight.

I gave a false proposition at the beginning: reconstruction based on ThinkPHP (no reason). After a period of practice, I found that this is a completely wrong way of thinking, and the pitfalls encountered in it will not be mentioned here.

First of all, don’t think about rewriting everything based on namespace, but on a partial basis.

The final result after thinking is to transform the Model layer based on the namespace as the goal, so that the Model layer resources in the system can be reused under the new framework. Because in theory the Model layer only deals with data and has the lowest degree of coupling.

However, some problems were also discovered during the transformation process. The Model layer couples business logic and is even linked to system environments such as session and cache. It is not a pure Db operation, but contains a lot of business code. This means that this part of the code is undergoing preliminary transformation. Once completed, it cannot be reused in a new framework.

These problematic areas also indirectly prove the correctness of some basic programming ideas: the essence of OOP is code reuse; the direct effect of the PSR series of specifications on improving code reuse; the impact of the rationality of code layering on code maintainability etc.; global variables have an extremely negative impact on code reusability.

What is progressive refactoring?

The basic principle of gradual reconstruction is compatibility, not overthrowing and starting over. As long as things become pushing back and starting over, it is not refactoring, it is simply rewriting. In a small entrepreneurial team, when it comes to rewriting, are u kidding me?

Compatibility is the starting point and process of refactoring, and reuse is the result; new functions can be developed based on new frameworks, but at the same time existing function codes can be reused, so This is a process.

The above has introduced the experience of refactoring the old PHP system based on namespace, including namespace and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template