How do we fix this?
The acyclic dependency principle states that dependencies between packages must be a directed acyclic graph (DAG)—that is, the dependency graph must have no cycle. If we do see a cycle in the graph, then it is a sign of a design problem.
When we encounter such a problem, we must refactor the code so that the specific dependent function is moved to a separate package. In this example, suppose that there's some code in package A that is used by the package internally and also used by package E. This dependency is basically E -> A.
We can then take this code and move it to a new package F. After this change, packages A and E would both depend on package F, effectively removing the cyclic dependency:
After this refactoring, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access