views:

734

answers:

5

Hi!

I have a project called Data which is a data layer. In this project, all files are just lying in the top folder. I have enumerations, POCOs, repositories, partial classes and so on.

If i want to move those files into subfolders, what would be the preffered folder name for each folder? Is there any convention?

The "Repositories" folder is pretty obvious, but where should i keep POCOs and enumerations?

Thanks

+5  A: 

I tend to use project folders as a way of separating out sub namespaces. So in your case, perhaps a folder called Repositories, which has class in the Data.Repositories namespace. Note, for partial classes, each file needs to be in the same namespace.

Timothy Carter
+2  A: 

Best prectice is to divide entities in folders by object model meaning, not by type.

Veton
+2  A: 

A good practice is to name the folder after the name of the project.

Design Guidelines for Developing Class Libraries has a set of Guidelines for Names

The last item should be of paticular interest for you:

Alfred Myers
+1  A: 

If it is not clear how to group the classes by usage or object model meaning, just leave them all in one folder. Using subfolders don't give values if they don't organise the classes in a meaningful way.

Dividing folders by type, e.g. enumerations, POCOs, repositories, partial classes etc is not likely to be useful.

You may wish to use a subfolder for generated code that should not be edited.

Also remember you can have folders within the solution explorer that are not part of the file system. Given how costly (in time) it is in some source code control systems to move files between directories, I would consider starting of just using msdev folders until you are clear on the structure you want.

There is no need to put each enumeration in its own file, if an enumeration is only used by one class, it is valid to put it in the same file as the class. E.g the PersonSex enumeration can be put in the person.cs file. Likewise if you have a lot of small and closely related classes, consider putting them in the same file.

Ian Ringrose
A: 

I (currently - changes based on project) tend to use this approach when naming assemblies/projects/namespaces in a SAAS/Web style project)

  • CompanyName.
    • ProductName.
      • Data.
      • Business. (references data)
      • Model. (POCO and interfaces - referenced by all)
      • Services. (WCF service layer)
      • ServiceClient. (referenced by web clients)
      • Web. (web client business layer)
        • ViewModel. (view specific model)
        • {client facing product segment} [Commerce, CMS, CRM, Reporting, etc.]

To explain the Services/Service Client...I use an IoC (currently StructureMap) that allows my WebClient to either speak directly to the Business layer or to be redirected to speak through the ServiceClient through Services to the Business layer. This gives me the flexibility to either deploy my app layer to my web applications or to distribute pieces of my business layer (app layer) to different servers by way of WCF/SOA principles.

Andrew Siemer