使每个类成为一个单独的程序集

发布于 2024-10-28 02:19:43 字数 207 浏览 2 评论 0原文

我不是一个经验丰富的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一杯敬自由 2024-11-04 02:19:43

这不是一个好主意。将关注点放在一个程序集中。但每个程序集不是一个类。
如果更改两个类,则需要发送两个程序集而不是一个。你赢得了什么?

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?

绻影浮沉 2024-11-04 02:19:43

这是一个非常糟糕的主意。

  • 它不会节省您的编译时间。
  • 这会花费你的运行时间。
  • 这会让你的开发变得复杂
    并花费你很多时间。
  • 这会导致错误。
  • C# 编译器中的其他机制负责保存
    编译时如果只改变 1
    文件(顺便说一句,每个文件一个类
    是标准 - 但也有一些

如果您计划将它们作为单独的组件重新分发(将它们安装给最终用户),则需要将它们放入单独的程序集中 我敢打赌这不是你的情况。

您可以拆分为程序集的示例:

  • 两个完全不同的程序 - clock.exefacebookAlbumViewer.exe
  • 3 层软件:MyProgramDataModel.dllMyProgramBusinessLogic.dllMyProgramGui.exe
    将来您将发布一个新的 MyProgramDataModel.dll(现在可与 Oracle 而不是 MySql 一起使用),因此您只需部署该组件。它只有在大型且复杂的软件上才有意义。

It is a very bad idea.

  • It will not save you compile-time.
  • It will cost you run time.
  • It will complicate your development
    and spend you a lot of your time.
  • It will lead to bugs.
  • Other mechanisms in the C# compiler take care of saving
    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:

  • two entirely different programs - clock.exe and facebookAlbumViewer.exe
  • 3-tier software: MyProgramDataModel.dll, MyProgramBusinessLogic.dll and MyProgramGui.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.
时光清浅 2024-11-04 02:19:43

你说的是客户端软件。一个规模相当大的项目,有几百个类 ->对于客户端软件来说,几百个 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 -

流星番茄 2024-11-04 02:19:43

您将节省多少编译时间?您将花费多少时间为每个课程添加新项目?

不要浪费你的时间,让编译器完成他的工作。你的时间比编译器的时间更有价值。

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.

感受沵的脚步 2024-11-04 02:19:43

如果您所讨论的所有这些类都在执行不同的工作,并且也可以根据它们正在执行的业务分开,那么我认为将它们中的每个类单独组装是可以接受的。然而你也应该小心这个问题,否则你的应用程序可能会变成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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文