您如何为应用程序中的一个或几个客户组织特定代码?
当您实现客户特定的代码时,您如何组织它?
- 您直接在代码中编写 if 语句吗? (if (customer == 20) then blah blah)
- 你有一个特殊的 dll 来放置该客户的所有代码吗?
- 您是否编写了一种“用户退出”,即可以在单独的 dll 中重载的命名函数?
- 或者您是否使用库/框架来实现这一点?
- 或者更好的方法?
When you implement customer-specific code, how do you organize it?
- Do you write if-Statements directly in your code ? (if (customer == 20) then blah blah)
- Do you have a special dll where you put all of the code for that customer?
- Do you program a kind of "user exits", i.e. named functions that can be overloaded in a separate dll?
- Or do you use a library / framework for that?
- Or a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
if 语句解决方案存在一个缺陷,即您可能需要为每个新客户在很多地方修改代码。更好的方法是将您想要改变的行为封装在接口中,然后让现有代码委托该任务到该接口的实例。然后设计就可以适应任意数量的不同行为。
更进一步,将代码设计为框架,然后为每个使用该框架以及任何特定于客户的代码的客户创建一个应用程序项目。该框架可以进行版本控制和(内部)发布,从而使客户应用程序不受框架后续版本的影响。
我建议您看一下《灵活、可靠的软件:使用模式和敏捷开发》这本书。它是围绕这个问题建立的。
The if-statement solution has the flaw that you may need to modify your code many places for each new customer. A better way is to encapsulate the behaviour you want to vary in an interface, and then letting the existing code delegate the task to an instance of this interface. The design is then ready for any number of different behaviours.
Take it even one step further and design your code as a framework and then create an application project for each customer that uses the framework in addition to any customer-specific code. The framework can be version controlled and (internally) released, allowing customer applications to be unaffected by later releases of the framework.
I would recommend that you take a look at the book "Flexible, Reliable Software: Using Patterns and Agile Development". It is built up around this very question.