php - Several functional modules share part of the code. I want to modify one of the functions. How to avoid destroying other functions?
怪我咯2017-05-16 13:08:42
0
13
1284
Part of the code in several functional modules is common. If you want to modify one of the functions, you need to modify the common code. How to avoid damaging other functions when you are not sure which functions reference this code?
Add a mark judgment at the function entrance. If the mark is true, follow the logic you wrote yourself. Otherwise, the original logic will remain unchanged. Examples are as follows:
default() original, newFunc() new, main() public calling part
In this case, then this method is not public So, change this method, according to the actual situation, Add parameters, judge by parameters Re-differentiate the business logic, split the original method, and recombine it
Write the "public code" as "public class", and then change the organizational structure to the "mediator" model to reduce the coupling between the "public class" and other classes. Inherit the "public class" where changes are needed, and make modifications. part
Add a mark judgment at the function entrance. If the mark is true, follow the logic you wrote yourself. Otherwise, the original logic will remain unchanged. Examples are as follows:
default() original, newFunc() new, main() public calling part
This is the simplest modification. . .
In this case, then this method is not public
So, change this method, according to the actual situation,
Add parameters, judge by parameters
Re-differentiate the business logic, split the original method, and recombine it
Write the "public code" as "public class", and then change the organizational structure to the "mediator" model to reduce the coupling between the "public class" and other classes. Inherit the "public class" where changes are needed, and make modifications. part