Best way to organize the files in my project

◇◆丶佛笑我妖孽 提交于 2019-12-21 02:55:13

问题


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?


回答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.

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

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.




回答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.



来源:https://stackoverflow.com/questions/997149/best-way-to-organize-the-files-in-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!