php - 几个功能模块公用了部分代码,想修改其中一个功能,如何避免破坏其他功能
怪我咯
怪我咯 2017-05-16 13:08:42
0
13
1162

几个功能模块有部分代码是公用的,想修改其中一个功能,需要修改公用代码,在不确定哪些功能引用了这段代码的情况下,如何避免破坏其他功能

怪我咯
怪我咯

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

reply all(13)
伊谢尔伦

Abstract it
Then write multiple methods to implement the abstract method, and different functional points implement different business logic.

漂亮男人

The easiest way. Copy it and quote it separately.

淡淡烟草味

For example, if you want to modify the A method of a public module, and there are other modules that also use A, you can write another A1 method instead of modifying A.

滿天的星座

You can overwrite the public part of the code of the subclass, and you can modify the function of one of them at will

世界只因有你

Create a category Override this method in the category Import the category in this file.

左手右手慢动作

Write a subclass to inherit this public method, encapsulate the parts that need to be modified into the subclass, and use this subclass for the target module.

曾经蜡笔没有小新

Create a new method. A way to package others.

function pre() {}

function now() {
    var result = pre()
    // todo sth
    // todo sth
    return newResult
}
伊谢尔伦

If your modification changes the behavior of the original code, it is best to create a new one
If the new code has a lot of overlap with the original code, you can consider extracting the reusable parts

某草草

Two ways:

  1. Add flag type parameters to the method, and perform different processing according to different flags in the method

  2. Rewrite one more method

黄舟

Let’s modify that method by classifying it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!