2
\$\begingroup\$

Please have a look at the code below:

ClassLibrary1 has a structure as follows:

Namespace com.app.test 
Public Class Class1
End Class
End Namespace

ClassLibrary2 has a structure as follows:

Namespace com.app.test 
Public Class Class2
End Class
End Namespace

WindowsApplication1 has a structure like this:

Imports com.app.test
Public Class Form1
 Dim c1 As Class1
 Dim c2 As Class2
End Class

Notice that Class1 and Class2 are in different projects (DLL's), but they have the same namespace. Is this poor practice? I have never seen it done before.

asked Mar 18, 2013 at 21:12
\$\endgroup\$
0

2 Answers 2

4
\$\begingroup\$

It is indeed better component design as @Tyriar mentioned, but it is also very common that the namespaces are being used among the projects. This is not always a wrong design.


Let assume that you are implementing plug-ins. And every plug in has own assembly (normally). There, namespaces can be shared.

PluginA.dll

Namespace CompanyName.SolutionName.ProjectName.PlugInNamespace
{
 Class PlugInA {}
}

PluginB.dll

Namespace CompanyName.SolutionName.ProjectName.PlugInNamespace
{
 Class PlugInB {}
}

Better practice for your case would be the sub-namespacing.

ClassLibrary1

Namespace Com.App.Test.FunctionalityGroupA
Public Class Class1
End Class
End Namespace

ClassLibrary2

Namespace Com.App.Test.FunctionalityGroupB 
Public Class Class2
End Class
End Namespace

WindowsApplication1

Imports Com.App.Test.FunctionalityGroupA
Imports Com.App.Test.FunctionalityGroupB 
Public Class Form1
 Dim c1 As Class1
 Dim c2 As Class2
End Class
answered Mar 19, 2013 at 12:31
\$\endgroup\$
3
\$\begingroup\$

Yes it is poor practice, there is no reason really to deviate from best practice which is to have the last part of your namespace match the project name like this:

CompanyName.SolutionName.ProjectName

Say there is a company called "ABC Solutions" and they have a web project called "ABC Editor", here are some example project names:

AbcSolutions.AbcEditor.Data
AbcSolutions.AbcEditor.Database
AbcSolutions.AbcEditor.Web

Also you're using Java style package naming which I've never actually seen in C# before, it really looks quite odd :)

answered Mar 19, 2013 at 10:48
\$\endgroup\$
2
  • \$\begingroup\$ Thanks. +1. The problem is that there are two DLLs for the Business Logic Layer. Therefore based on your answer I should have: com.application.businesslogiclayer.DLL1 and com.application.businesslogiclayer.DLL2. DLL1 and DLL2 will be named better. Can you confirm that I have understood your answer correctly? \$\endgroup\$ Commented Mar 19, 2013 at 11:47
  • \$\begingroup\$ What is the reason for their separation? Can a meaningful name be used to differentiate them? If they are they are all relate to one another maybe you should consider merging them or more clearly defining what makes each different? \$\endgroup\$ Commented Mar 19, 2013 at 12:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.