开发者

An exception to avoid copy and paste code?

There are many files in our project that would call a Facebook api. And the call is complicated, spanning usually 8 lines or more, just for the argument values.

In this case, we can make it into a function, and place that function in a common_library.php, but doing so would just change the name of the function call from the Facebook API function to our name, and we still need to repeat the 8 lines of arguments. Each time, the call is 开发者_StackOverflow社区very similar, but with slight variations to the argument values.

In that case, would copy and paste be needed no matter what we do?


"Each time, the call is very similar, but with slight variations to the argument values."

If you pass differing parameters each time, you're not actually repeating yourself. The fact that the function call spans 8 lines is more concerning, and there are many ways to try and ameliorate that. However, without more information on what this function actually does, it's hard to offer any advice.


Introduce Parameter Object might be the best solution for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜