使每个类成为一个单独的程序集
我不是一个经验丰富的 .Net 程序员,因此提出了这个问题。
将每个(主要)类放在单独的程序集中,这样我选择更改可执行文件的任何类的实现都不需要重新编译,这是一个非常糟糕的主意吗?或者我的想法是否意味着由于运行时加载等而导致严重的性能问题?
我知道这个问题很模糊,但也许有具体的指导方针来说明什么应该放在单独的程序集中,什么通常不应该放在
一起提前致谢
I am not an experienced .Net programmer, hence this question.
Is it a terribly bad idea to put each (major) class in a separate assembly, so that whichever class's implementation I choose to change the executable need not be recompiled? Or does my idea imply serious performance issues due to runtime loading etc.?
I know the question is vague, but maybe there are specific guidelines as to what should be put in a separate assembly and what genereally shouldn't
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这不是一个好主意。将关注点放在一个程序集中。但每个程序集不是一个类。
如果更改两个类,则需要发送两个程序集而不是一个。你赢得了什么?
It's not a good idea. Put concerns together in one assembly. But not a single class per assembly.
If you change two classes, you need to ship two assemblies instead of one. What have you won?
这是一个非常糟糕的主意。
并花费你很多时间。
编译时如果只改变 1
文件(顺便说一句,每个文件一个类
是标准 - 但也有一些
。
如果您计划将它们作为单独的组件重新分发(将它们安装给最终用户),则需要将它们放入单独的程序集中 我敢打赌这不是你的情况。
您可以拆分为程序集的示例:
clock.exe
和facebookAlbumViewer.exe
MyProgramDataModel.dll
,MyProgramBusinessLogic.dll
和MyProgramGui.exe
将来您将发布一个新的
MyProgramDataModel.dll
(现在可与 Oracle 而不是 MySql 一起使用),因此您只需部署该组件。它只有在大型且复杂的软件上才有意义。It is a very bad idea.
and spend you a lot of your time.
compile-time if you only change 1
file (by the way one class per file
is the standard - but there are some
exceptions)
You need to put things in separate assemblies if you plan to redistribute them (install them to your end-users) as separate components. I'll bet that is not your scenario.
examples where you might split to assemblies:
clock.exe
andfacebookAlbumViewer.exe
MyProgramDataModel.dll
,MyProgramBusinessLogic.dll
andMyProgramGui.exe
in the future you ship a new
MyProgramDataModel.dll
(that now works with Oracle instead of MySql), so you deploy only that component. It will only make sense on big and complicated software.你说的是客户端软件。一个规模相当大的项目,有几百个类 ->对于客户端软件来说,几百个 DLL 是不可接受的,而且这种做法并不常见。
装配体并没有那么大,无需担心。每个类都有一个 DLL,您将公开所有代码结构 - MyApp.dll、MyApp.MainForm.dll、MyApp.DatabaseLogic.UserAuthentication.dll -
You talk about client software. A decent-sized project with a few hundred classes -> a few hundred DLLs is not acceptable for client software and this is not common practice.
Assemblies just aren't that big to worry about it. With a DLL per class you'll be exposing all of your code structure - MyApp.dll, MyApp.MainForm.dll, MyApp.DatabaseLogic.UserAuthentication.dll -
您将节省多少编译时间?您将花费多少时间为每个课程添加新项目?
不要浪费你的时间,让编译器完成他的工作。你的时间比编译器的时间更有价值。
How much time will you save on compilation? How much time will you spend on adding a new project for each class?
Do not waste your time, let compiler do his job. Your time worth more than compiler's.
如果您所讨论的所有这些类都在执行不同的工作,并且也可以根据它们正在执行的业务分开,那么我认为将它们中的每个类单独组装是可以接受的。然而你也应该小心这个问题,否则你的应用程序可能会变成DLL地狱!
If all of these classes you are talking about are doing different jobs and also can be seperated by the business they are doing then, putting each of them to seperate assembly is acceptable I suppose. However you also should be careful about this issue, else your applications might turn into a DLL hell!