473,237 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

Namespace organization

Any advice on how to organize my core class library project into
sub-namespaces? What are the general rules of thumb regarding
cross-namespace references? Can I have a class in namespace A have a
function or a property that returns a class from a different namespace?

For example, lets say I have a root namespace called ACME for my class
library project. Under the root namespace are classes such as Individual,
Address, etc. I also have a namespace defined for financial classes, called
ACME.Financial, which contains classes such as Invoice and Transaction.
Under Financial is a subnamespace called Discounts
(ACME.Financial.Discounts). A second namespace under the root, called
ACME.Groups, contains classes such as Group, GroupPlan, etc.

ACME
ACME.Financial
ACME.Financial.Discounts
ACME.Groups

Now, if I'm coding something for the GroupPlan class in ACME.Groups, is it
ok (I know it's possible but is it acceptable) to return an object of type
ACME.Financial.Invoice from the ACME.Groups.GroupPlan class or should I
stick to classes contained within the local namespace boundary (ACME.Groups)
or higher (ACME)?

Any thoughts or articles discussing Namespace coding best practices (all I
could find were ones about naming standards - not enough detail regarding
class layout) would be appreciated.

- Dave
Aug 12 '05 #1
5 4234
I do not know of an article that describes your concerns.

I am working on a namespace standard at the moment for Microsoft IT to use
internally, so that we may get some better consistency. In my case, I've
spoken with dozens of developers in different IT teams, and in each case,
they are largely sticking to a namespace structure that is much flatter than
you are implying. Namespaces aren't being used to differentiate to the
detail that you are suggesting.

I would suggest that you consider that your class library is specific to a
particular application that is tied to a specific business process within
your company. In that sense, the namespace should be
ACME.Area.Process.Application where 'Area' is the functional area of your
user's business process (Finance, Marketing, CustomerService, Product,
Partner, etc) and 'Process' is the business process that your application
supports (for example, for financial operations, you may have something like
'Invoice', 'Portal', or 'Reconciliation'). Application would be the
namespace of the application itself. Within MS, this is usually some
unrelated name or acronym... like Longhorn or Whitehorse (only the IT folks
can get pretty creative :-).

Using multiple namespaces within an application is done, but somewhat
sparingly. One fairly complex application I worked on had three namespaces:
one root and two child, for 400+ classes. For the most part, a namespace
tied directly to an assembly. In other words, all of the classes in that
namespace were contained in that assembly. (in the aforementioned app,
there were three assemblies).

So, the best advice I can come up with: if you are creating one assembly,
create one namespace.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Dave Slinn" <ds****@accesscomm.ca> wrote in message
news:eU**************@TK2MSFTNGP10.phx.gbl...
Any advice on how to organize my core class library project into
sub-namespaces? What are the general rules of thumb regarding
cross-namespace references? Can I have a class in namespace A have a
function or a property that returns a class from a different namespace?

For example, lets say I have a root namespace called ACME for my class
library project. Under the root namespace are classes such as Individual,
Address, etc. I also have a namespace defined for financial classes,
called ACME.Financial, which contains classes such as Invoice and
Transaction. Under Financial is a subnamespace called Discounts
(ACME.Financial.Discounts). A second namespace under the root, called
ACME.Groups, contains classes such as Group, GroupPlan, etc.

ACME
ACME.Financial
ACME.Financial.Discounts
ACME.Groups

Now, if I'm coding something for the GroupPlan class in ACME.Groups, is it
ok (I know it's possible but is it acceptable) to return an object of type
ACME.Financial.Invoice from the ACME.Groups.GroupPlan class or should I
stick to classes contained within the local namespace boundary
(ACME.Groups) or higher (ACME)?

Any thoughts or articles discussing Namespace coding best practices (all I
could find were ones about naming standards - not enough detail regarding
class layout) would be appreciated.

- Dave

Aug 16 '05 #2

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:5_********************@comcast.com...

Using multiple namespaces within an application is done, but somewhat
sparingly. One fairly complex application I worked on had three
namespaces: one root and two child, for 400+ classes. For the most part,
a namespace tied directly to an assembly. In other words, all of the
classes in that namespace were contained in that assembly. (in the
aforementioned app, there were three assemblies).

So, the best advice I can come up with: if you are creating one assembly,
create one namespace.

Nick,

Interesting - it's not the approach I use. I'd find 130 classes in a flat
structure a little unmanageable. Do you use folders in your VS projects to
organize the classes at a more detailed level? When I use folders, my
namespace religously follows the folder hierarchy. So I use
folders/namespaces to represent the coarse-level logical structure of the
application (not the deployment/assembly structure). But it's probably an
approach I brought over from the Java world - I don't have much experience
of what others do.

The .NET Class Library actually seems to follow a model that is closer to
what I do - it's certainly more granular than an assembly, although maybe
not as granular as the OP's proposal.

----
Nigel Norris


Aug 16 '05 #3
Nigel Norris <no****@nospam.com> wrote:
Interesting - it's not the approach I use. I'd find 130 classes in a flat
structure a little unmanageable. Do you use folders in your VS projects to
organize the classes at a more detailed level? When I use folders, my
namespace religously follows the folder hierarchy. So I use
folders/namespaces to represent the coarse-level logical structure of the
application (not the deployment/assembly structure). But it's probably an
approach I brought over from the Java world - I don't have much experience
of what others do.
I always follow that religiously too, although I don't necessarily
include the base hierarchy in the folder structure (eg if all the
namespaces in an assembly started with Foo.Bar.Baz, I would take that
as the top level of the hierarchy - so Foo.Bar.Baz.Wotsit would just be
in a directory called Wotsit under the solution).

Another habit I've brought over from the Java world is putting each
type in its own file - with the exception of short enums and delegates.
For those, I tend to have a single file, Enums.cs and Delegates.cs
respectively, which contains all the short enums/delegates for that
namespace. Of course, for larger enums (such as HttpStatusCode) I'd
devote a file just to that enum.

(On the other hand, I've also started porting some conventions from the
..NET world to my recent Java programming - in particular, prefixing
interfaces with I and using Pascal case for enums and constants, rather
than shouting.)
The .NET Class Library actually seems to follow a model that is closer to
what I do - it's certainly more granular than an assembly, although maybe
not as granular as the OP's proposal.


There certainly aren't many namespaces with huge numbers of classes -
with the notable exceptions of System.Windows.Forms which is absolutely
massive.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 16 '05 #4

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nigel Norris <no****@nospam.com> wrote: [snip] I always follow that religiously too, although I don't necessarily
include the base hierarchy in the folder structure (eg if all the
namespaces in an assembly started with Foo.Bar.Baz, I would take that
as the top level of the hierarchy - so Foo.Bar.Baz.Wotsit would just be
in a directory called Wotsit under the solution).

[snip]

My understanding from a previous employer is in Java, your namespace hierchy
should start with "tld.companyname.projectname.XXX"
For example; the Cells classes in MS Excel might be in the
"Com.Microsoft.Excel.WorkSheet" namespace.

I started doing something similar with .NET, just leaving the tld off. But
to be honest, I'm starting to think that is excessive in .NET. Maybe it was
necessary in Java because of the directory structure, and in .NET, I'm just
creating needless & cumbersome organization.

Do you guys have the tld, company, and/or project included in your .NET
namespaces?

I've got to say though, that above the initial company.project, I as much or
as little namespace hierchy as I feel comfortable with ... ussually
something like :
company.project.model
company.project.pages
company.project.controls
company.project.usersecurity
company.project.utilities.database
company.project.utilities.crypto
.... etc ...

Regards,
John
Aug 16 '05 #5
John <Pl**********@To.the.group.com> wrote:
I always follow that religiously too, although I don't necessarily
include the base hierarchy in the folder structure (eg if all the
namespaces in an assembly started with Foo.Bar.Baz, I would take that
as the top level of the hierarchy - so Foo.Bar.Baz.Wotsit would just be
in a directory called Wotsit under the solution). [snip]

My understanding from a previous employer is in Java, your namespace hierchy
should start with "tld.companyname.projectname.XXX"


That's true of namespaces in Java, but not in .NET.
For example; the Cells classes in MS Excel might be in the
"Com.Microsoft.Excel.WorkSheet" namespace.

I started doing something similar with .NET, just leaving the tld off.
Yes - that's the convention.
But to be honest, I'm starting to think that is excessive in .NET.
Maybe it was necessary in Java because of the directory structure,
and in .NET, I'm just creating needless & cumbersome organization.
It's not particularly *necessary* in either Java or .NET, but it helps
to keep your namespace separate from those of other companies.
Do you guys have the tld, company, and/or project included in your .NET
namespaces?
I prefer to use company name and then project name, but sometimes just
"overarching project name" followed by a slightly more fine-grained
project name. I'd certainly feel less than entirely happy about a
commercial namespace in just one level.
I've got to say though, that above the initial company.project, I as much or
as little namespace hierchy as I feel comfortable with ... ussually
something like :
company.project.model
company.project.pages
company.project.controls
company.project.usersecurity
company.project.utilities.database
company.project.utilities.crypto
... etc ...


Yup, those are perfectly reasonable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dsellers | last post by:
Are there any large scale / complex examples of namespace organization available for review? I am architecting a project that is a bit outside my scope of experience and I am looking for some help....
1
by: Steven T. Hatton | last post by:
I think Danny was one cup of coffee shy of full consciousness when he wrote this, but the gist of it makes sens to me: "C++ Project Organization Guidelines Last updated May 26, 2005....
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
1
by: J | last post by:
I'm early in my C# larval stage, so I'd like a little direction to help understand good code organization. Take for example a program I have written in another language that does the following: ...
4
by: Jason Pettys | last post by:
In an ASP.NET project I am setting the content type of my .ascx and ..aspx files to Embedded Resource for a separate reason. When I do this they get embedded as "RootNamespace.Filename" but I...
5
by: Dave Slinn | last post by:
Any advice on how to organize my core class library project into sub-namespaces? What are the general rules of thumb regarding cross-namespace references? Can I have a class in namespace A have a...
7
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
1
by: shapper | last post by:
Hello, Lately I have been working with ASP.NET MVC and C#. I have been building a lot of code and I am struggling to find a good way to organize it. I am posting some of the code I have...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.