Use of friends in C++ software: an empirical investigation
Use of friends in C++ software is widely considered as poor programming practice. However, little empirical evidence exists to support this belief. In this paper, the results of a case-study based investigation into the use of friends in object-oriented software are described. Four C++ systems of varying sizes were analysed and data related to friends collected for each. Class metrics were collected from each of the systems. Five hypotheses were then investigated. Results showed a lack of statistical significance with any of the class metrics collected. No evidence was found to support the hypothesis that classes declared as friends of other classes used inheritance any less than other classes. Strong evidence was found, however, to support the hypothesis that, firstly, friends tended to be found in classes deep in the inheritance hierarchy; secondly, that classes not engaging in inheritance use friends considerably more than classes that do. Empirical evidence also suggests that friends are used primarily as a means for facilitating operator overloading. The results in this paper highlight the need for more investigation in this area and into the wider issues of class coupling.
friends c++ empirical investigation object-oriented hypothesis