您如何组织大型项目的课程?

发布于 2024-07-16 05:44:03 字数 1228 浏览 12 评论 0原文

我们的应用程序中有大量功能,可以非常具体地描述为模块。 通常有某种设置对话框,然后当用户单击“确定”时,它会配置一个进程来运行并运行该进程。 有时,他们的参与程度更高,用户会打开新对话框并在该对话框上工作一段时间,执行许多对底层数据库进行更改的操作。

我通常会得到几个标准类

ConfigPanel.cs
ConfigPanelData.cs
ProcessRunner.cs
ApiWrapper.cs (for calling the process from somewhere else)

如果我有一个更多的端到端模块,它可能是 WorkerPanel.cs WorkerData.cs SetupOptions.cs(运行之间保持面板状态) 库/无论后端StuffINeedToSupportModule 现在,每个ApiWrapper

都有一个文件夹:

UI/Panels/
    Module1Panel.cs
    Module2Panel.cs
UI/PanelData/
    Module1PanelData.cs
    Module2PanelData.cs
UI/PanelManagers
    Module1PanelManager.cs
    Module2PanelManager.cs
Core/Module1/
    Module1.cs
    Module1Helpers.cs
Core/Module2/
    Module2.cs
    Module2Helpers.cs

如您所见,所有内容都真正分散开来。 由于有 50 多个模块,这些文件夹并没有真正组织起来。 即使按照子系统将它们分解,它们仍然是一团糟。 将所有内容放在一起以便所有内容都按功能而不是类类型分隔,这会是糟糕的设计吗?

Module1/
    Module1Panel.cs
    Module1PanelData.cs
    Module1PanelManager.cs
    Module1PanelLib.cs
    Module1PanelWrapper.cs
Module2/
    Module2Panel.cs
    Module2PanelData.cs
    Module2PanelManager.cs
    Module2PanelLib.cs
    Module2PanelWrapper.cs

您如何组织课程?有哪些优点/缺点?

We have a ton of features in our application that can be described very concretely as a module. The usually have some sort of setup dialog, then when the user clicks ok, it configures a process to run and runs that process. Sometimes they are more involed and the user will open up the new dialog and work on the dialog for a while, doing many things that make changes to the underlying database.

I typically end up with several standard classes

ConfigPanel.cs
ConfigPanelData.cs
ProcessRunner.cs
ApiWrapper.cs (for calling the process from somewhere else)

If I had a more end to end module it might be
WorkerPanel.cs
WorkerData.cs
SetupOptions.cs (panel state persisted between runs)
Lib/WhateverBackendStuffINeedToSupportModule
ApiWrapper

Right now there are folders for each one:

UI/Panels/
    Module1Panel.cs
    Module2Panel.cs
UI/PanelData/
    Module1PanelData.cs
    Module2PanelData.cs
UI/PanelManagers
    Module1PanelManager.cs
    Module2PanelManager.cs
Core/Module1/
    Module1.cs
    Module1Helpers.cs
Core/Module2/
    Module2.cs
    Module2Helpers.cs

As you can see, everything is really spread out. With 50+ modules those folders aren't really organized. Even breaking them up by subsystem, they are still a mess. Would it be bad design to just put everything together so everything is separated by function rather than class type?

Module1/
    Module1Panel.cs
    Module1PanelData.cs
    Module1PanelManager.cs
    Module1PanelLib.cs
    Module1PanelWrapper.cs
Module2/
    Module2Panel.cs
    Module2PanelData.cs
    Module2PanelManager.cs
    Module2PanelLib.cs
    Module2PanelWrapper.cs

How do you organize your classes and what are the advantages / disadvantages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

一身仙ぐ女味 2024-07-23 05:44:03

仅仅放置会是糟糕的设计吗?
一切都在一起,所以一切都是
按功能而不是按功能分隔
类类型?

没有通用规则,这取决于具体情况、您的个人喜好以及代码中的更改模式。
不过,我建议执行以下操作:

  • 在超类中保留尽可能多的通用代码,以消除任何冗余。 也许某些子类就不再需要了。
  • 我不确定“模块”是什么意思,但我建议在同一项目中使用命名空间+子目录来分隔这些内容,而不是使用单独的程序集。 仅将程序集用于部署分离目的和类似目的。
  • 你提到的那些“助手”类听起来有点代码臭味。 它们可能违反了面向对象的原则。 查看此链接以获取更多信息:http://blogs. msdn.com/nickmalik/archive/2005/09/06/461404.aspx。 也许您可以重新组织代码,减少对此类的需求,同时获得更清晰的 OO 设计的好处?

Would it be bad design to just put
everything together so everything is
separated by function rather than
class type?

There's no general rule, it depends on the situation, your personal preferences and change patterns in your code.
However I would suggest doing the following:

  • Keep as much of the common code in the superclasses to eliminate any redundancy. Maybe then some of the subclasses won't even be needed.
  • I'm not sure what you mean by "modules", but I would recommend separating the stuff using namespaces+subdirectories in the same project and not by using separate assemblies. Use assemblies only for deployment separation purposes and similar stuff.
  • Those "helper" classes you mention sound a bit code-smelly. They could be a violation of OO principles. Check out this link for more info: http://blogs.msdn.com/nickmalik/archive/2005/09/06/461404.aspx. Maybe you can reorganize the code, reduce the need for such classes AND get a benefit of a cleaner OO design at the same time?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文