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.

\$\endgroup\$
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
\$\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 :)

\$\endgroup\$
  • \$\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\$ – w0051977 Mar 19 '13 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\$ – Daniel Imms Mar 19 '13 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.