简体   繁体   English

我应该为模块化创建DLL吗?

[英]Should I create DLLs for modularity?

I'm working on creating an app that will parse MSDN articles for meta-information such as the article title and other articles that are in the same collection. 我正在创建一个应用程序来解析MSDN文章中的元信息,例如文章标题和同一集合中的其他文章。 This app also has a GUI front-end. 这个应用程序还有一个GUI前端。

I'm interested in making this program more modular by separating the front-end from the back-end and the back-end into two parts -- one that handles the retrieval and general parsing of an HTML-document and one that does more specific parsing related to MSDN itself. 我有兴趣通过将前端与后端和后端分成两部分来使这个程序更加模块化 - 一个用于处理HTML文档的检索和一般解析,另一个用于更具体的解析解析与MSDN本身有关。 The idea being that this will allow custom UIs to be slapped onto the back-end and allow for the app to be able to parse other sites (perhaps Google search results) just by plugging-in a different DLL. 这个想法是,这将允许自定义UI被打到后端,并允许应用程序只需通过插入不同的DLL来解析其他站点(可能是谷歌搜索结果)。

My understanding is that you would normally create DLLs to share code across different applications. 我的理解是,您通常会创建DLL以跨不同的应用程序共享代码。 However, in this case, I'm only looking for modularity for this one particular application. 但是,在这种情况下,我只是在寻找这个特定应用程序的模块化。 Is it still appropriate to create DLLs in this case? 在这种情况下创建DLL仍然合适吗? Or should I be considering a different option, such as just glomming all of the classes together into a single assembly? 或者我应该考虑一个不同的选项,例如将所有类组合成一个组件?

I should note that I'm relatively new to programming, so even if the answer is "no", then this will still be a good exercise for me to learn from. 我应该注意到我对编程比较陌生,所以即使答案是“不”,那么这对我来说仍然是一个很好的练习。 If that's the case, I'd like to know if this exercise should be modified in anyway to make it more appropriate. 如果是这种情况,我想知道是否应该修改此练习以使其更合适。

I think that your idea of using DLLs in this situation is a good idea. 我认为你在这种情况下使用DLL的想法是个好主意。 There is no appreciable extra cost in using DLLs (possibly a bit more startup cost at the most). 使用DLL没有明显的额外成本(最多可能需要更多的启动成本)。 And even if you are currently only planning on using them in this one application, it doesn't hurt to still plan for future changes. 即使您目前只计划在这个应用程序中使用它们,仍然计划未来的更改也没有什么坏处。 There is always a good chance that the DLLs can be used with little or no modification in another application if needed. 如果需要,DLL很可能在很少或没有修改的情况下在另一个应用程序中使用。

In addition, splitting it into separate DLLs for modularity might even help with the design and development process. 此外,将其拆分为单独的DLL以实现模块化甚至可能有助于设计和开发过程。 It makes "sharing" global data more difficult (and that is probably a good thing). 它使“共享”全球数据变得更加困难(这可能是一件好事)。 If everything is in one monolithic assembly, there may be some tendency to just grab some data from some other place. 如果所有内容都在一个整体组件中,那么可能有一些趋势只是从其他地方获取一些数据。 If that data lives in another assembly, then that potentially bad practice is less likely to happen. 如果该数据存在于另一个程序集中,那么这种可能不好的做法就不太可能发生。 It may force the developer into rethinking how to solve issues. 它可能会迫使开发人员重新思考如何解决问题。

DLLs can help with maintenance of your application. DLL可以帮助维护您的应用程序。 If you have future updates and/or bug fixes, you can update specific DLLs as opposed to the entire application. 如果您有将来的更新和/或错误修复,您可以更新特定的DLL而不是整个应用程序。 This will also help reduce your testing surface area. 这也有助于减少测试表面积。

During development it will also be a bit easier to stub out certain classes/DLLs and swap in the actual DLLs later once developed. 在开发过程中,将某些类/ DLL删除并在以后开发时交换实际的DLL也会更容易一些。

I wouldn't go crazy and put every class in its own DLL. 我不会发疯,把每个类放在自己的DLL中。 From a high-level there should be a clear grouping of classes that should be together. 从高层开始,应该有一个明确的类别组合在一起。

There is several advantage to make a DLL: 制作DLL有几个好处:

  • the DLL can be changed independently from the caller program (front-end) DLL可以独立于调用者程序(前端)进行更改
  • the DLL can be distributed by itself, independently from the caller problem (front-end) DLL可以自己分发,独立于调用者问题(前端)
  • if several simultaneously running software use the same DLL the memory footprint will be smaller 如果多个同时运行的软件使用相同的DLL,则内存占用将更小

It also comes with a cost: 它还带有一个成本:

  • you can't use simple inheritance scheme to extend DLL classes 你不能使用简单的继承方案来扩展DLL类
  • sharing global data is still possible but more difficult (some may say this force better design, but it's still a constraint) 共享全球数据仍然是可能的,但更难(有些人可能会说这更好的设计,但它仍然是一个约束)
  • unit testing of code included in a DLL is more difficult 包含在DLL中的代码的单元测试更加困难
  • there are installation issues (the dll must be put in special places and registered, depending how you use it) 有安装问题(dll必须放在特殊的地方并注册,具体取决于你如何使用它)

But the main point regarding modularity is that DLL is still a half measure. 但关于模块化的主要观点是DLL仍然是一半。 Even if we ignore costs, it is not much better than a lib or even just reusing existing classes. 即使我们忽略了成本,它也不比lib更好,甚至只是重用现有的类。 The main advantages are for resellers, not really for software developers, except if you expect third party contributors. 主要优势是经销商,而不是软件开发人员,除非您期望第三方贡献者。 And the called functions are still running in the same process that the main program. 并且被调用的函数仍然在与主程序相同的进程中运行。

If you want a real clean cut for modularity you could use a real multi-tiers architecture with separate processes for front-end and back-end and a communication layer between them (say TCP sockets). 如果你想要一个真正的模块化整体,你可以使用真正的多层架构,前端和后端有独立的进程,它们之间有一个通信层(比如TCP套接字)。 That is usually both more versatile and more robust, and not much more complex when done early enough in project life. 这通常既更通用又更强大,而且在项目生命中尽早完成时并不复杂得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM