带有命令的目录结构。

发布于 2024-07-08 07:29:01 字数 303 浏览 8 评论 0原文

我有一个 winforms 项目,我们使用命令模式。 我们正在尝试清理目录结构并使其保持一致。

我们正在尝试决定是否应该有一个根命令文件夹。 您认为什么目录结构更好?

项目
--命令
----添加命令
----减法命令
----插入命令
----删除命令

项目
--计算
----添加命令
----减法命令
--数据库
----插入命令
----删除命令

I have a winforms projects and we use the command pattern. We are trying to clean up our directory structure and make it consistent.

We are trying to decide if we should have a root commands folder or not. What do you think is better for a directory structure?

Project
--Commands
----AddCommand
----SubtractCommand
----InsertCommand
----DeleteCommand

or

Project
--Calculation
----AddCommand
----SubtractCommand
--Database
----InsertCommand
----DeleteCommand

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

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

发布评论

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

评论(2

一袭白衣梦中忆 2024-07-15 07:29:01

似乎一般问题是您是否想按动作/动词(即命令文件夹)或目标/名词(数据库、计算等文件夹)进行分类。 无论您采取哪条路线,您都可以尝试保持一致(对视图和小部件采取与对命令等相同的方法)。

我能想到的一些注意事项:

  • 是否还有其他内容也可以放入 Project/Database/etc 文件夹中,或者仅包含命令? 如果只有命令,则只需拥有一个 Commands 文件夹可能会简化事情,因此您不必为每个新命令决定一个好的顶级文件夹。 例如,您将对数据库值进行计算的命令放在哪里?

  • 如果您将拥有大量命令(其中“大”的定义有些不明确),那么拥有额外级别的目录可能会更好。

根据我的经验,如何组织代码的问题总是令人恼火。 如果所有其他方法都失败了,您应该选择一个选项并执行它,如果您确定做出了错误的选择,则稍后重新安排。

It seems like the general question is whether you want to categorize by actions/verbs (i.e. a Commands folder) or by targets/nouns (folders for Database, Calculation, etc). Whichever route you take, you might try to be consistent (take the same approach with Views and Widgets as you do with Commands, etc).

A few considerations I can think of:

  • Are there other things that would also go in the Project/Database/etc folders, or only commands? If only commands, it might simplify things to just have a Commands folder, so you don't have to decide on a good top-level folder for each new command. For instance, where do you put a command that does Calculations on Database values?

  • If you're going to have a large number of commands (where "large" is somewhat ill-defined), having an additional level of directories might be nice.

In my experience, the question of how to organize code is always irritating. If all else fails, you should just pick an option and go with it, and rearrange later if you decide you made the wrong choice.

浅语花开 2024-07-15 07:29:01

我个人喜欢第二种选择,但我认为你也可以这样做:

Project
-Commands
--Calculation
----AddCommand
----SubtractCommand
--Database
----InsertCommand
----DeleteCommand

Just my 2 cents

Personally I like the second option but I think that you could also do something like this:

Project
-Commands
--Calculation
----AddCommand
----SubtractCommand
--Database
----InsertCommand
----DeleteCommand

Just my 2 cents

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