7

All my programming life I have been thinking that the cyclic dependency is the following:
GIVEN

  • package1
  • package2
    • subpackage2
  • package3

IF

  1. Class from package1 references class from package2
  2. Class from package2 references class from package3
  3. Class from package3 references class from package1

THEN
Project contains cyclic dependency package1 > package2 > package3 > package1.

This was a pretty huge surprise when Intellij's dependency viewer told me, that:

IF

  1. Class from package1 references class from package2
  2. Class from subpackage2 references class from package3
  3. Class from package3 references class from package1

THEN
Project contains cyclic dependency package1 > package2 > package3 > package1.

Could anybody, please, explain me what is the strict definition for cyclic dependency and why does Intellij show such weird results? Thanks.

11
  • 1
    Do you mean to say that your first example would not qualify as a cyclic dependency in IntelliJ's view? Or are you surprised that the 2nd example does? Commented Apr 7, 2016 at 16:57
  • @kaqqao Second one. I'm surprised that Intellij treats second example a cyclic dependency. Commented Apr 7, 2016 at 18:39
  • 1
    Well, the dependencies are transitive, so by virtue of depending on subpackage2 which in turn depends on package3, package2 itself depends on package3, thus forming the exact same graph as example 1. I'm more surprised other tools don't see it as a circle. Why do you see these examples as fundamentally different? Commented Apr 7, 2016 at 19:05
  • @ kaqqao : that should be the answer. Question is vague, one cannot go beyond your assertion. Commented Apr 8, 2016 at 13:39
  • @Jayan Not sure why this seems vague to you. It is clear that there is misconception between tools checking cyclic dependency. Their results are just not the same. Commented Apr 8, 2016 at 13:44

1 Answer 1

6
+50

The dependencies are transitive, so by virtue of depending on subpackage2 which in turn depends on package3, package2 itself depends on package3, thus forming the exact same graph as example 1. I'm more surprised other tools don't see it as a circle, as IntelliJ is correct here.

Sign up to request clarification or add additional context in comments.

1 Comment

The actual problem was actually in our internal tool which shows only direct cycles and skips transitive ones. So I was really surprised when old jdepend and our internal tool had same results. Thanks for pointing helping out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.