Cyclic namespaces in C #

How truly "evil" are circular namespace dependencies within the same assembly. I understand that using multiple assemblies changes and something like this won't compile, but what is the real risk of doing this within a single assembly?

+1


a source to share


3 answers


No risk - feel free to reference whatever you want on the same assembly.

However, this approach will make your application fragile and difficult to scale. The best approach is to try to keep your components as orthogonal as possible.



What the language and the compiler allow you to do is not necessarily what's best for long term development needs (bug fixes, scaling, new features, etc.). You should strive for free connection and high cohesion .

+2


a source


namespaces are a way to provide a logical organization for your code. They provide the ability to reuse names by applying them in a specific context. There is nothing wrong with classes in two namespaces depending on each other.



Cyclic depedance in assemblies is a little more complicated. Last I checked, visual studio does not directly resolve this type of relationship.

+1


a source


I don't think there are any risks per se, and in some cases this is naturally the natural way of doing things. System.Text.StringBuilder

obviously does System.String

, and I would be very surprised if nothing in the namespace System

was used StringBuilder

.

It's probably worth just checking your design as often as possible: ask the question if you can split the functionality into separate components. Quite often the answer will be "no", and then just proceed without guilt :)

+1


a source







All Articles