CRITICAL
Rule Definition
When two namespaces refer to each other through a call, the result is a circular dependency. Neither namespaces can function without the other, and so neither is reusable without the other. In some cases redesign may eliminate these dependencies. When circular references are necessary, redesign it to ensure reusability. The same problem happen when some classes from a namespace A inherit from classes of a namespace B and other classes from namespace B inherit from other classes from namespace A. This rule can be extended to circular dependencies for more than 2 namespaces (for example a namespace A call a namespace B that call a namespace C, that call namespace A).
Remediation
If there are circular relationships among namespaces, the partitioning is not clear and should be redesigned. Use CAST Enlighten to see all dependencies to fix.
Violation Code Sample
* Direct call sample:
namespace CyclicalCallsA
{
public static class ClassA
{
public static void f()
{
CyclicalCallsB.ClassB.g();
}
}
}
namespace CyclicalCallsB
{
public static class ClassB
{
public static void g()
{
CyclicalCallsA.ClassA.f();
}
}
}
* Call due to inheritance:
namespace CyclicalCallsWIA
{
public class ClassWIA
{
public static void f()
{
CyclicalCallsB.ClassB.g();
}
}
}
namespace CyclicalCallsWIB
{
public class ClassWIB : CyclicalCallsWIA.ClassWIA
{
public static void g()
{
}
}
}
Reference
CISQ rules: ASCMM-MNT-7, ASCRM-RLB-13.
Related Technologies
.Net
Technical Criterion
Architecture - Multi-Layers and Data Access
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.