When we chatted about Visual Studio architecture tooling in Ranger chalk talk sessions today and especially when I was watching Suhail demonstrate the use of the architecture tooling, I started think about what circular references really mean. Looking at the enormous diagrams generated when analyzing the PetShop or Tailspin sample applications the actual code and the analysis results seem to get lost in all the noise.
I decided to write some simple code, defining classes in four namespaces and creating instances where a class method calls another class method, which in turn calls the original class method. Take note of ClassA2.Test() and ClassB3.Test() …
We then generate a Dependency Graph by Namespace, enabling all three currently available analyzers as shown below.
So what happens?
- Namespaces and associated classes that are acting as a hub … get called and call … are shown in blue.
- Namespaces and associated classes that not called by anyone … are unreferenced … are shown in violet.
- Namespaces and associated classes that calls others, which in turn call the classes again and thereby creating a circular reference, are highlighed in red.
When we create a sequence diagram off the ClassA2.Test() method, to get a clearer view, we suddenly realize that the circular reference is a bad one, which will result in the system eating itself up … like a recursive call that recursively calls itself. At some point the system will throw a no memory exception and implode.
Changing the code as follows, maintains a circular reference between classes, nut not a recursive call that would sooner than later result in a system blow-up. … still showing a circular reference, but not one that will implode ourselves.
… changes the view as follows:
Cool stuff …