Measuring Impact of Dependency Injection on Software Maintainability
Abstract
:1. Introduction
2. Dependency Injection
3. Measuring the Impact of DI on Maintainability
- Does change in DI proportion impact CBO? We believe this is an important question to address because previous research has argued that DI should reduce coupling, and therefore reduce CBO [3]. It should follow that an inverse relationship between DI and CBO (increase in DI will decrease CBO) can be quantified. We use experimental analysis to determine whether that inverse relationship exists.
- How effective is CBO in quantifying maintainability? In our paper, we utilize CBO to assess maintainability. We also use the normalization techniques proposed by Okike and Osofisan [12] to allow for more informative analysis. We critique whether normalized CBO is useful in analyzing maintainability in the context of DI.
- How should DI inform coupling in the software system? This is the motivation behind our proposal for the new metrics, DCBO and DCE. DCBO and DCE consider the additional developer “effort” required when DI is not used in the software system, and we argue that it would decrease overall maintainability. We developed the open-source CKJM-Analyzer [10] tool that utilizes DCBO and DCE to determine DI proportion. We perform an analysis using the tool and discuss the results.
3.1. Dependency Injection Weighted-Coupling between Objects
3.2. Dependency Injection Detection Algorithm
3.3. Normalized CBO and Maintainability
Algorithm 1 Detecting instances of DI patterns. |
4. Evaluation
4.1. Experimental Projects
- No DI—The class instantiates an class, and the class instantiates a class.
- Param DI—The class instantiates a class, and then instantiates an class while injecting the class.
- XML DI—The XML file injects an class into the class, and the XML file also injects a class into the class.
4.2. Open-Source Projects
5. Answering Research Questions
- Answer to “Does change in DI proportion impact CBO?” Experimental results in Table 1 show that XML DI using Spring Framework [2] introduces a small coupling overhead, which increases CBO in small projects. The experimental projects controlled for all other metrics and LOC, but larger projects will be helpful in determining whether large-scale DI use significantly impacts CBO. After controlling for LOC, open-source projects also observed an increase in CBO as DI increased. While the study gave an overall analysis on the impact of DI on coupling, it did not identify projects using Spring Framework or other DI frameworks. While the use of a DI framework would suggest developer intent in using DI, it leaves out other projects that use DI without a framework. More research should be conducted in determining whether developers intended to use DI, as discussed by Yang et al. [4], and whether a DI threshold can be quantified in order to identify a project as utilizing DI.
- Answer to “How effective is CBO in quantifying maintainability?” CBO alone does not appear to be sufficient in quantifying maintainability. Other metrics have been used to assess maintainability, including lack of cohesion of methods (LCOM) and response for class (RFC) as analyzed by Razina and Janzen [3], but difficulties remain in determining how effective the values are as a robust metric [12]. More research will be needed to determine whether other metrics can better inform the maintainability of a software system.
- Answer to “How should DI inform coupling in the software system?” DCE and DCBO inform additional developer effort required when DI is not used. This paper covers a partial aspect of how DI can impact the maintainability of a project. In particular, we argued that DI via parameter or XML injection instead of new object (default object) construction improves maintainability by reducing the number of files that need to be changed should the injected class’ constructor parameters change. CKJM-Analyzer, DCE and DCBO explicitly incorporate DI as a factor in weighing coupling differently. One future work of CKJM-Analyzer would be determining which portions of the software are using the CWD/MWD patterns and replacing them with the CND/MND patterns. Another work would be making a cross-platform CKJM-Analyzer, as right now, it is only usable on the Windows OS.
6. Related Work
6.1. Coupling Literature Review
6.2. Dependency Injection Literature Review
7. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Murgia, A.; Tonelli, R.; Counsell, S.; Concas, G.; Marchesi, M. An empirical study of refactoring in the context of FanIn and FanOut coupling. In Proceedings of the 18th Working Conference on Reverse Engineering, Limerick, Ireland, 17–20 October 2011; pp. 372–376. [Google Scholar]
- Johnson, R.; Hoeller, J. Expert One-on-One J2EE Development without EJB; Wiley Publishing: Hoboken, NJ, USA, 2004. [Google Scholar]
- Razina, E.; Janzen, D.S. Effects of dependency injection on maintainability. In Proceedings of the 11th IASTED International Conference on Software Engineering and Applications, Cambridge, MA, USA, 19–21 November 2007; pp. 7–12. [Google Scholar]
- Yang, H.Y.; Tempero, E.; Melton, H. An empirical study into use of dependency injection in java. In Proceedings of the 19th Australian Conference on Software Engineering, Perth, WA, Australia, 26–28 March 2008. [Google Scholar]
- Lee, Y.; Chang, K.H. Reusability and maintainability metrics for object-oriented software. In Proceedings of the 38th Annual on Southeast Regional Conference, Clemson, SC, USA, 7–8 April 2000; pp. 88–94. [Google Scholar]
- Crasso, M.; Mateos, C.; Zunino, A.; Campo, M. Empirically assessing the impact of dependency injection on the development of Web Service applications. J. Web Eng. 2010, 9, 66–94. [Google Scholar]
- Roubtsov, S.; Serebrenik, A.; van den Brand, M. Detecting modularity “smells” in dependencies injected with Java annotations. In Proceedings of the 14th European Conference on Software Maintenance and Engineering, Madrid, Spain, 15–18 March 2010; pp. 244–247. [Google Scholar]
- Laigner, R.; Kalinowski, M.; Carvalho, L.; Mendonça, D.; Garcia, A. Towards a Catalog of Java Dependency Injection Anti-Patterns. In Proceedings of the 33rd Brazilian Symposium on Software Engineering, Salvador, Brazil, 23–27 September 2019; pp. 104–113. [Google Scholar]
- Spinellis, D. Chidamber and Kemerer Java Metrics. Available online: http://www.spinellis.gr/sw/ckjm/ (accessed on 22 September 2020).
- CKJM-Analyzer. Available online: https://github.com/Narnian12/ckjm-analyzer (accessed on 1 June 2022).
- Fowler, M. Inversion of Control Containers and the Dependency Injection Pattern. 2004. Available online: https://martinfowler.com/articles/injection.html (accessed on 6 August 2020).
- Okike, E. An Evaluation of Chidamber and Kemerer’s Lack of Cohesion in Method (LCOM) Metric Using Different Normalization Approaches. Afr. J. Comput. ICT 2008, 1, 35–54. [Google Scholar]
- ckjm-di. Available online: https://github.com/Narnian12/ckjm-di (accessed on 1 August 2022).
- Lincke, R.; Lundberg, J.; Löwe, W. Comparing Software Metrics Tools. In Proceedings of the 2008 International Symposium on Software Testing and Analysis, Seattle, WA, USA, 20–24 July 2008; pp. 131–142. [Google Scholar]
- Oman, P.; Hagemeister, J. Metrics for assessing a software system’s maintainability. In Proceedings of the Proceedings Conference on Software Maintenance, Orlando, FL, USA, 9–12 November 1992; pp. 337–344. [Google Scholar]
- Wagey, B.C.; Hendradjaya, B.; Mardiyanto, M.S. A proposal of software maintainability model using code smell measurement. In Proceedings of the International Conference on Data and Software Engineering, Yogyakarta, Indonesia, 25–26 November 2015; pp. 25–30. [Google Scholar]
- Emam, K.E.; Benlarbi, S.; Goel, N.; Rai, S.N. The confounding effect of class size on the validity of object-oriented metrics. IEEE Trans. Softw. Eng. 2001, 27, 630–650. [Google Scholar] [CrossRef]
- ckjm-di-projects. Available online: https://github.com/Narnian12/ckjm-di-projects (accessed on 1 August 2022).
- Tempero, E.; Anslow, C.; Dietrich, J.; Han, T.; Li, J.; Lumpe, M.; Melton, H.; Noble, J. The Qualitas Corpus: A curated collection of Java code for empirical studies. In Proceedings of the 2010 Asia Pacific Software Engineering Conference, Sydney, NSW, Australia, 30 November–3 December 2010; pp. 336–345. [Google Scholar]
- Garcia, S.; Herrera, F. An Extension on ‘Statistical Comparisons of Classifiers over Multiple Data Sets’ for all Pairwise Comparisons. J. Mach. Learn. Res. 2008, 9, 2677–2694. [Google Scholar]
- Anwer, S.; Adbellatif, A.; Alshayeb, M.; Anjum, M.S. Effect of coupling on software faults: An empirical study. In Proceedings of the 2017 International Conference on Communication, Computing and Digital Systems, Islamabad, Pakistan, 8–9 March 2017; pp. 211–215. [Google Scholar]
- Újházi, B.; Ferenc, R.; Poshyvanyk, D.; Gyimóthy, T. New conceptual coupling and cohesion metrics for object-oriented systems. In Proceedings of the 2010 10th IEEE Working Conference on Source Code Analysis and Manipulation, Timisoara, Romania, 12–13 September 2010; pp. 33–42. [Google Scholar]
- Saidulu, A. Assessing Weight of the Coupling between Objects towards Defect Forecasting in Object Oriented Programming. Glob. J. Comput. Sci. Technol. 2014, 14, 35–39. [Google Scholar]
- Muhammad, R.; Nadeem, A.; Sindhu, M.A. Vovel metrics—novel coupling metrics for improved software fault prediction. PeerJ Comput. Sci. 2021, 7, e590. [Google Scholar] [CrossRef] [PubMed]
- Johnson, R.; Hoeller, J.; Donald, K.; Sampaleanu, C.; Harrop, R.; Risberg, T.; Arendsen, A.; Davison, D.; Kopylenko, D.; Pollack, M.; et al. The spring framework-reference documentation. Interface 2004, 21, 27. [Google Scholar]
- Gamma, E.; Helm, R.; Johnson, R.; Johnson, R.E.; Vlissides, J. Design Patterns: Elements of Reusable Object-Oriented Software; Addison-Wesley: Boston, MA, USA, 1995. [Google Scholar]
Project | DI | LOC | CBO | NCBO | DCBO | NDCBO | CA | CE | DCE |
---|---|---|---|---|---|---|---|---|---|
No DI | 0.00 | 28 | 1.00 | 0.50 | 1.00 | 0.50 | 0.50 | 0.50 | 0.50 |
Param DI | 0.25 | 31 | 1.33 | 0.57 | 1.17 | 0.54 | 0.67 | 0.67 | 0.50 |
XML DI | 0.33 | 42 | 1.33 | 0.57 | 1.00 | 0.50 | 0.33 | 1.00 | 0.67 |
Project | Version | DI | LOC | CBO | NCBO | DCBO | NDCBO | CA | CE | DCE |
---|---|---|---|---|---|---|---|---|---|---|
advanced-gwt | 2.0.8 | 0.21 | 33,199 | 9.17 | 0.90 | 7.92 | 0.89 | 3.33 | 5.83 | 4.59 |
ant | 1.4.1 | 0.25 | 54,268 | 8.99 | 0.90 | 7.87 | 0.89 | 4.46 | 4.53 | 3.41 |
colt | 1.2.0 | 0.40 | 101,730 | 7.73 | 0.89 | 6.11 | 0.86 | 3.64 | 4.08 | 2.47 |
ine fitjava | 1.1 | 0.21 | 5178 | 4.56 | 0.82 | 4.07 | 0.80 | 2.22 | 2.34 | 1.85 |
ganttproject | 1.11.1 | 0.29 | 66,120 | 6.95 | 0.87 | 5.94 | 0.86 | 3.43 | 3.51 | 2.51 |
hsqldb | 1.8.0.2 | 0.25 | 145,646 | 10.96 | 0.92 | 9.57 | 0.91 | 5.48 | 5.48 | 4.09 |
ireport | 0.5.2 | 0.16 | 21,378 | 5.09 | 0.84 | 4.68 | 0.82 | 2.54 | 2.54 | 2.14 |
jchempaint | 2.0.12 | 0.31 | 880,275 | 8.99 | 0.90 | 7.58 | 0.88 | 4.45 | 4.54 | 3.13 |
jfreechart | 1.0.0 | 0.32 | 160,004 | 10.17 | 0.91 | 8.34 | 0.89 | 4.53 | 5.64 | 3.81 |
jgap | 3.6.3 | 0.34 | 68,071 | 8.40 | 0.89 | 6.88 | 0.87 | 3.97 | 4.43 | 2.92 |
JHotDraw | 7.0.9 | 0.36 | 19,070 | 6.71 | 0.87 | 5.49 | 0.85 | 3.31 | 3.40 | 2.18 |
jhotdraw | 6.0.1 | 0.25 | 66,843 | 9.04 | 0.90 | 7.89 | 0.89 | 4.36 | 4.67 | 3.53 |
log4j | 1.2.15 | 0.35 | 37,925 | 6.83 | 0.87 | 5.63 | 0.85 | 3.41 | 3.42 | 2.22 |
Mars | 4.5 | 0.30 | 108,126 | 8.89 | 0.90 | 7.57 | 0.88 | 4.44 | 4.44 | 3.13 |
pdfbox | 2.0.1 | 0.30 | 158,833 | 11.64 | 0.92 | 9.81 | 0.91 | 5.54 | 6.09 | 4.26 |
picocontainer | 1.3 | 0.33 | 8931 | 8.16 | 0.89 | 6.83 | 0.87 | 4.08 | 4.08 | 2.75 |
poi | 2.5.1 | 0.16 | 124,773 | 8.10 | 0.89 | 7.44 | 0.88 | 4.05 | 4.05 | 3.39 |
wro4j-core | 1.5.0 | 0.18 | 29,059 | 7.45 | 0.88 | 6.65 | 0.87 | 3.11 | 4.34 | 3.54 |
Algorithms | p |
---|---|
Low NCBO vs. High NCBO | 0.01 |
Algorithms | p |
---|---|
Low DI NCBO vs. High DI NCBO | 1.0 |
Project | Version | DI | LOC | CBO | NCBO | DCBO | NDCBO | CA | CE | DCE |
---|---|---|---|---|---|---|---|---|---|---|
ireport | 0.5.2 | 0.16 | 21,378 | 5.09 | 0.84 | 4.68 | 0.82 | 2.54 | 2.54 | 2.14 |
poi | 2.5.1 | 0.16 | 124,773 | 8.10 | 0.89 | 7.44 | 0.88 | 4.05 | 4.05 | 3.39 |
wro4j-core | 1.5.0 | 0.18 | 29,059 | 7.45 | 0.88 | 6.65 | 0.87 | 3.11 | 4.34 | 3.54 |
fitjava | 1.1 | 0.21 | 5178 | 4.56 | 0.82 | 4.07 | 0.80 | 2.22 | 2.34 | 1.85 |
jgap | 3.6.3 | 0.34 | 68,071 | 8.40 | 0.89 | 6.88 | 0.87 | 3.97 | 4.43 | 2.92 |
log4j | 1.2.15 | 0.35 | 37,925 | 6.83 | 0.87 | 5.63 | 0.85 | 3.41 | 3.42 | 2.22 |
JHotDraw | 7.0.9 | 0.36 | 19,070 | 6.71 | 0.87 | 5.49 | 0.85 | 3.31 | 3.40 | 2.18 |
colt | 1.2.0 | 0.40 | 101,730 | 7.73 | 0.89 | 6.11 | 0.86 | 3.64 | 4.08 | 2.47 |
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Sun, P.; Kim, D.-K.; Ming, H.; Lu, L. Measuring Impact of Dependency Injection on Software Maintainability. Computers 2022, 11, 141. https://doi.org/10.3390/computers11090141
Sun P, Kim D-K, Ming H, Lu L. Measuring Impact of Dependency Injection on Software Maintainability. Computers. 2022; 11(9):141. https://doi.org/10.3390/computers11090141
Chicago/Turabian StyleSun, Peter, Dae-Kyoo Kim, Hua Ming, and Lunjin Lu. 2022. "Measuring Impact of Dependency Injection on Software Maintainability" Computers 11, no. 9: 141. https://doi.org/10.3390/computers11090141
APA StyleSun, P., Kim, D. -K., Ming, H., & Lu, L. (2022). Measuring Impact of Dependency Injection on Software Maintainability. Computers, 11(9), 141. https://doi.org/10.3390/computers11090141