Introduction
Dependency cycles—situations where two or more components depend on each other—are notorious "maintenance killers" in software engineering. They erode modularity, complicate testing, and significantly increase the cognitive load required for developers to understand the system. While many static analysis tools can detect these cycles, there is surprisingly little empirical evidence regarding how human developers actually resolve them in real-world scenarios.
This paper focuses specifically on two-class dependency cycles (e.g., Class A depends on Class B, and Class B depends on Class A). These are the most frequent type of circular dependency and often represent the final, critical step in untangling much larger, multi-component architectural knots.
Methodology
The researchers developed a systematic four-step pipeline to study the evolution and resolution of these cycles within version control history.
- Detection: Using
githistory and theDependsreverse engineering tool, the team identified dependency graphs before and after every commit in their dataset. - Identification: They pinpointed "fix commits"—instances where a two-class cycle existed in version $N$ but was successfully resolved in version $N+1$.
- Manual Inspection: A team of researchers manually inspected hundreds of code snippets. They did not just look at the two cyclic classes; they traced the entire calling chain to see if the logic was moved, deleted, or abstracted.
- Pattern Synthesis: Using a decision tree strategy, they categorized the fixes into recurring "untangling patterns."
To validate the predictability of these patterns, they trained a Multi-layer Perceptron (MLP) classifier to see if the internal structure of a cycle (dependency types like call, create, or extend) and its "design context" could predict which refactoring pattern a developer would choose.
Dataset and Scope
The study analyzed 38 high-quality open-source projects across diverse domains, including data processing, databases, and UI frameworks.
In total, the researchers identified 587 successful untangling cases and 69 unsuccessful (counterintuitive) cases. The diversity of the dataset, spanning communities like Apache, Google, Facebook, and Alibaba, ensures that the identified patterns are representative of broad industry practices.
Patterns of Cycle Resolution
The analysis revealed five primary successful recurring patterns used by developers:
- Removing Unused/Deprecated Code (40.0%): The most frequent solution. This suggests that many cycles are "ghosts" of old designs that were never properly cleaned up.
- Moving Code to a Third Class (23.4%): Shifting responsibility to a new or existing neutral class to break the direct circularity.
- Moving Code Between Cyclic Files (14.8%): Realigning methods with the class they most closely relate to, often fixing "feature envy" code smells.
- Shortening Call Chains (12.1%): Bypassing an intermediate class to call a dependency directly, thereby removing the return link.
- Leveraging Built-In Features (1.0%): Replacing a custom dependency with a standard library feature, such as using Java Reflection instead of a direct class reference.
Key Insights
A major finding is that context is king. The researchers discovered that you cannot decide how to fix a cycle just by looking at the two classes involved. Including the "design context"—how neighboring classes interact with the cycle—significantly improved the MLP model's ability to predict the correct refactoring pattern, increasing the F1-score from 0.52 to 0.64 for complex patterns.
Additionally, the study highlighted the "Cycle Shift" trap. About 10% of "fixes" are actually failures where the developer accidentally shifts the dependency to a parent class, a child class, or a third utility class, creating a new (and sometimes larger) cycle.
Conclusion
This empirical study demonstrates that while dependency cycles are complex, their resolutions follow predictable patterns. The high F1-score (0.86) achieved by the MLP model for certain patterns suggests that automated refactoring recommendations are feasible. Future work involves building IDE plugins to provide real-time guidance to developers, helping them choose the most appropriate untangling pattern based on their specific design context.
Summary updated