I've been researching Java package structure and dependency patterns over the last few weeks. One of the common threads across the writings on the subject is the simple rule that package dependencies should form a directed acyclic graph (DAG). Author Robert Martin even formalized the Acyclic Dependencies Principle (ADP), which states
The dependency structure between packages must be a directed acyclic graph (DAG). That is, there must be no cycles in the dependency structure.
A few Java libraries do adhere to this simple rule. Namely, Spring Framework libraries (spring-core, spring-web, etc) and Google Guava.
However, to my surprise, the majority of leading open-source Java projects do not!
The following open-source projects have circular dependencies among packages:
Have I misunderstood the software engineering principle? Or do developers discount this package organization technique?
I can confirm that after the analysis of many java projects using JArchitect, many of them contains circular dependencies between packages, the reason is that many of them choose the "package by feature" rather than the "package by layer" approach.
Here's a good article talking about the difference between these two approachs.
Let's take as example some packages from the JDK
These packages are designed by feature, the regex feature is grouped in the java.util.regex package which need some security features from the java.security package and the security classes need also some regex functionalities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With