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?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(13)
Peter_Zhu

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

main()
{
  if ($flag) {
        NewFunc();
  }
  else
        Default();
}

或者直接修改default()
default($flag){
  if ($flag) {
        你改的逻辑
  }
  else
        原来的
}
}

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template