doupin1073 2013-07-18 19:48
浏览 32
已采纳

具有多个相关项目的代码组织

I'm working on a website project using WordPress that requires a few custom plugins. I want to keep the plugins modular, but a few of them require similar functionality. So, I find myself with conflicting goals:

  • Make each plugin self-contained and modular
  • Don't repeat code

For example, I have a need in two different plugins to output <select> elements based on a list of terms and some arguments. I wrote a function to accomplish this, but should I duplicate the function in both plugins? That seems like a maintenance nightmare, but if I don't, one plugin will depend on the other in a pretty arbitrary way. Is there some clever solution to this that I'm missing?

  • 写回答

1条回答 默认 最新

  • douguanyan9928 2013-07-18 19:57
    关注

    Consider the duplicate code. In particular, consider the number of functions and their length. If both plugins share only a couple formatting methods, it's not such a big deal to duplicate that code in order to keep the plugins self-contained.

    If the duplicate code is getting pretty hefty, start thinking about doing one of the following:

    1. Merge the plugins into a single plugin. Only do this if the two plugins fit into the same problem space. Take a good hard look at the plugins. There's a chance that what made them seem separate before was illusory and the fundamental behaviors are closely related.

    2. Extract the duplicate code into a third plugin which is a dependency of each of the plugins that share the code. Only do this if the duplicate code is related and make sense as a plugin.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线