Work with circular dependency

I wonder if anyone can advise any good ways to break the circular dependency between two classes in java! FindBugs offers the use of interfaces, so I wonder if anyone has any good experience with this type of problem!

Thanks in advance!

+8
java circular-dependency
source share
3 answers

Circular dependencies should not always be avoided. I would avoid them altogether, but stay in the small narrow corners of the system. In general, if the level of data access and the presentation level of a J2EE application is application dependent, I would say that this is bad because it means that everything needs to be compiled at a time, and testing is a nightmare. But this is not a problem if the list data structure and its type of iterator are circular dependent.

Since Findbugs suggests using interfaces to break circular dependency. I. Introduce an interface for at least one type of circle and make other classes use the interface everywhere. Do you need some sample code?

+6
source share

Suggest to read the principle of dependency inversion, for example. What is the dependency inversion principle and why is it important? or http://en.wikipedia.org/wiki/Dependency_inversion_principle

+5
source share

There is a blog post here about how Restructure101 was used to remove circular dependencies, "obfuscation", from Junit and a presentation from Lausanne JUG about how it was used to remove tangles from Icefaces.

Regarding the discussion of whether cyclic dependencies are bad, I suggest reading Uncle Bob's Solid Principles .

Disclaimer: I work for Headway Software as the developers of Restructure101.

+2
source share

All Articles