Strong Circular Dependency Between Packages

Dependency cycles between name spaces (CD) is a special instance of cycles between modules [1]. Often, only weak circular dependencies between two packages are considered: there must be one path connecting some class in a package A to some class in another package B, and another path connecting some class in B with some class in A. This antipattern is stronger: it requires that there is one path that connects a class in A with a class in B and then returns to A. For instance, it is not possible to break this antipattern by splitting packages. This antipattern is more difficult to remove as the path must be broken through refactoring. The presence of this antipattern implies that the participating packages cannot be deployed and maintained separately. In particular, if these name spaces were deployed in several runtime modules (jars), this would create a circular dependency between those jars.

This antipattern is implemented as graph query (motif) as follows:

motif cd
select inside1,inside2,outside1,outside2
where "inside1.namespace==inside2.namespace" and "inside1.namespace!=outside1.namespace" and "inside1.namespace!=outside2.namespace"
connected by outgoing(inside1>outside1)[1,1] and incoming(outside2>inside2)[1,1] and path(outside1>outside2)[0,*]
group by "inside1.namespace"


  1. W. Stevens, G. Myers, and L. Constantine. 1979. Structured design. In Classics in software engineering, Edward Nash Yourdon (Ed.). Yourdon Press, Upper Saddle River, NJ, USA 205-232.