Over the past few weeks, I have been studying Java package structure and dependency patterns. One common thread in the scriptures on this subject is a simple rule, according to which the package dependencies must constitute a directed acyclic graph (DAG). Author Robert Martin even formalized the Principle of Acyclic Dependencies (ADP), which states
The dependency structure between packages must be a directed acyclic graph (DAG). That is, there should not be cycles in the dependency structure.
Several Java libraries adhere to this simple rule. Namely, the Spring Framework (spring -core, spring -web, etc.) and Google Guava .
However, to my surprise, most of the leading open source Java projects do not !
The following open source projects have circular dependencies between packages:
- Netflix Hystrix (each package is part of a cycle!)
- AWS SDK
- Commons-lang
- Commons Collection
- Dagger
- Google gson
- Google guice
- Hibernate orm
- Hibernate validator
- Jackson core
- Jod time
- Play framework
- Junit
- Logback
- Jetty
- Aspectj
- Nettie
- java.util
- java.lang
Am I misunderstood the principle of software development? Or can developers opt out of this package organization?
References:
java spring package dependencies circular-dependency
Elliot
source share