Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaces - How deep is too deep

We are currently reorganising some of our services projects so their naming is more logical. We have the following structure:

Djp.Services.Type. ServiceName

This seems to make sense as a logical grouping, however what I want to know is, is it acceptable to have further levels under this based on the folders in the project. For example one project is called

Djp.Services.Management.Data

Under this project we have a "POCO" folder and a "Repositories" folder, which means, in principal, objects under these folders will have a namespace 5 levels deep.

Is this depth of namespace something that should avoided, or is it perfectly reasonable?

like image 555
MrEdmundo Avatar asked Oct 08 '10 11:10

MrEdmundo


2 Answers

Any namespace that follows the logic of your application structure is fine - regardless of the length.

like image 181
Bozho Avatar answered Oct 18 '22 09:10

Bozho


We have a namespace seven layers deep, with an eighth symbol on the end for the class. The dropdown in the top-left of Visual Studio 2010 that allows you to choose the class within this file doesn't fit our fully qualified class name, and when you mouse over it, there's no tooltip, so the only way to find the class name is to undock the source view and stretch it across two monitors.

I know this is dependent on the total length of the names, and not necessarily the number of nested namespaces, but I'm going to go ahead and define this as "too deep" :)

like image 4
mo. Avatar answered Oct 18 '22 10:10

mo.