What is the best way to organize the files in your project?
组织项目中文件的最佳方法是什么?
For example do you put all user controls in a separate folder or do you place them in a sub folder? Do you have business logic folder? A helper classes folder?
例如,您是将所有用户控件放在单独的文件夹中还是将它们放在子文件夹中?你有业务逻辑文件夹吗?帮助程序类文件夹?
I used to organize my projects like this:
我曾经组织过这样的项目:
Project/User Controls/Module Name/ Project/Classes/Module Name/
项目/用户控制/模块名称/项目/类/模块名称/
Now I am learning more towards something like this: Project/Module Name/User Controls/ Project/Module Name/Classes/
现在我正在学习更多这样的事情:项目/模块名称/用户控制/项目/模块名称/类/
What is the best way? Especially if the project gets really big? What type of folder structure should exist?
什么是最好的方法?特别是如果项目真的很大?应该存在哪种类型的文件夹结构?
3 个解决方案
#1
First the purpose of folder separation is to be an extra level of documentation, to let the programmers find code easier. That means you should not have extra levels "just to organize stuff". That excludes folders named Classes, Controls, etc.
首先,文件夹分离的目的是提供更高级别的文档,让程序员更容易找到代码。这意味着你不应该有额外的级别“只是为了组织东西”。这排除了名为Classes,Controls等的文件夹。
Some examples:
If you work on a thee tier App it would make a lot of sense to have something like:
如果你在一个应用程序层上工作,有一些东西是很有意义的:
Project\Tier (Model|Controller|etc)\Classname
If you program is big to the point of having separate functional areas I would go with:
如果你的程序很大,我可以选择单独的功能区:
Project\Functional Area\Tier (Model|Controller|etc)\Classname
Project \ Functional Area \ Tier(Model | Controller | etc)\ Classname
That is particularly usefull when sub-teams work on the different functional areas.
当子团队在不同的职能领域工作时,这尤其有用。
Also refrain from very deep folder trees (IMHO, more than depth 4 is too much) and keep your folder names compact. Some tools might have limitations on path size as low as 255 chars, so this is one place where brevity has its place.
还要避免非常深的文件夹树(恕我直言,超过深度4太多)并保持您的文件夹名称紧凑。有些工具可能会限制路径大小低至255个字符,因此这是一个简洁的地方。
#2
I separate our major chunks into projects - makes it very easy to reuse.
我将我们的主要部分分成了项目 - 使其易于重用。
Within a project I do folders (and names) by functional areas.
在一个项目中,我按功能区域做文件夹(和名称)。
That's as far as I go on a generic basis - the needs of the project determine any further partitioning.
这就是我的通用基础 - 项目的需求决定了任何进一步的分区。
#3
I agree with the other answers that suggest naming folders by purpose and not type (i.e. call a folder Model, not Classes and include only data-oriented classes in that folder). Additionally I like to keep all Controls and Data/Model related classes in their own separate projects that are not allowed to reference each other. This can help you enforce the separation between view and model in your code which is generally a good thing.
我同意其他答案建议按目的命名文件夹而不是类型(即调用文件夹Model,而不是Classes,并且只包含该文件夹中的面向数据的类)。另外,我喜欢将所有与控件和数据/模型相关的类保存在不允许相互引用的独立项目中。这可以帮助您在代码中强制实现视图和模型之间的分离,这通常是一件好事。
#1
First the purpose of folder separation is to be an extra level of documentation, to let the programmers find code easier. That means you should not have extra levels "just to organize stuff". That excludes folders named Classes, Controls, etc.
首先,文件夹分离的目的是提供更高级别的文档,让程序员更容易找到代码。这意味着你不应该有额外的级别“只是为了组织东西”。这排除了名为Classes,Controls等的文件夹。
Some examples:
If you work on a thee tier App it would make a lot of sense to have something like:
如果你在一个应用程序层上工作,有一些东西是很有意义的:
Project\Tier (Model|Controller|etc)\Classname
If you program is big to the point of having separate functional areas I would go with:
如果你的程序很大,我可以选择单独的功能区:
Project\Functional Area\Tier (Model|Controller|etc)\Classname
Project \ Functional Area \ Tier(Model | Controller | etc)\ Classname
That is particularly usefull when sub-teams work on the different functional areas.
当子团队在不同的职能领域工作时,这尤其有用。
Also refrain from very deep folder trees (IMHO, more than depth 4 is too much) and keep your folder names compact. Some tools might have limitations on path size as low as 255 chars, so this is one place where brevity has its place.
还要避免非常深的文件夹树(恕我直言,超过深度4太多)并保持您的文件夹名称紧凑。有些工具可能会限制路径大小低至255个字符,因此这是一个简洁的地方。
#2
I separate our major chunks into projects - makes it very easy to reuse.
我将我们的主要部分分成了项目 - 使其易于重用。
Within a project I do folders (and names) by functional areas.
在一个项目中,我按功能区域做文件夹(和名称)。
That's as far as I go on a generic basis - the needs of the project determine any further partitioning.
这就是我的通用基础 - 项目的需求决定了任何进一步的分区。
#3
I agree with the other answers that suggest naming folders by purpose and not type (i.e. call a folder Model, not Classes and include only data-oriented classes in that folder). Additionally I like to keep all Controls and Data/Model related classes in their own separate projects that are not allowed to reference each other. This can help you enforce the separation between view and model in your code which is generally a good thing.
我同意其他答案建议按目的命名文件夹而不是类型(即调用文件夹Model,而不是Classes,并且只包含该文件夹中的面向数据的类)。另外,我喜欢将所有与控件和数据/模型相关的类保存在不允许相互引用的独立项目中。这可以帮助您在代码中强制实现视图和模型之间的分离,这通常是一件好事。