Evaluation of the ‘replace constructors with creation methods’ refactoring in Java systems

Evaluation of the ‘replace constructors with creation methods’ refactoring in Java systems

For access to this article, please select a purchase option:

Buy article PDF
(plus tax if applicable)
Buy Knowledge Pack
10 articles for £75.00
(plus taxes if applicable)

IET members benefit from discounts to all IET publications and free access to E&T Magazine. If you are an IET member, log in to your account and the discounts will automatically be applied.

Learn more about IET membership 

Recommend Title Publication to library

You must fill out fields marked with: *

Librarian details
Your details
Why are you recommending this title?
Select reason:
IET Software — Recommend this title to your library

Thank you

Your recommendation has been sent to your librarian.

Class constructors play an indispensable role in the Java language as a mechanism for object creation. However, little empirical evidence exists on constructors, trends in their composition and how a class with too many constructors might influence its understandability by developers. Herein, the authors investigate the applicability of the ‘replace constructors with creation methods’ (RCwCM) refactoring of Kerievsky in five Java systems. The RCwCM was manually applied to a set of classes from each of the five systems in classes containing three or more constructors. The benefits of this refactoring include improved code readability and encapsulation, program understanding and to a lesser extent possible elimination of code duplication. Within each of the five systems, evidence of scope for applying the RCwCM refactoring based on the number of classes with multiple constructors was found. However, problems were encountered that limited its application. These are the nature of inheritance and the different styles of accessing class constructors. In the former, account has to be taken of multiple dependencies if the class is not a leaf class; in the latter, the ‘super’ construct requires careful handling. When considered against the benefits that the RCwCM provides, care needs to be exercised. As with any refactoring effort, the short and long-term benefits need to be compared with the expense outlay (developer time and effort) as well as the opportunity cost.


    1. 1)
      • B. Foote , W. Opdyke , J. Coplien , D. Schmidt . (1995) Life cycle and refactoring patterns that support evolution and reuse.
    2. 2)
      • M. Fowler . (1999) Refactoring (improving the design of existing code).
    3. 3)
      • Johnson, R., Opdyke, W.: `Creating abstract superclasses by refactoring', Proc. ACM 1993 Computer Science Conf. (CSC'93), 1993, Indianapolis, USA, p. 66–73.
    4. 4)
      • R. Johnson , W. Opdyke . (1993) Refactoring and aggregation. Object technologies for advanced software.
    5. 5)
      • R. Johnson , B. Foote . Designing reusable classes. J. Object-Oriented Program. , 2 , 22 - 35
    6. 6)
      • Mens, T., van Deursen, A.: `Refactoring: emerging trends and open problems', Proc. First Int. Workshop on Refactoring: Achievements, Challenges, Effects (REFACE), University of Waterloo, 2003.
    7. 7)
      • T. Mens , T. Tourwe . A survey of software refactoring. IEEE Trans. Softw. Engng. , 2 , 126 - 139
    8. 8)
      • O'Cinneide, M., Nixon, P.: `Composite refactorings for Java programs', Proc. Workshop on Formal Techniques for Java Programs, ECOOP Workshops, 1998, Brussels, Belgium.
    9. 9)
      • Tourwe, T., Mens, T.: `Identifying refactoring opportunities using logic meta-programming', Proc. European Conf. on Software Maintenance and Reengineering (CSMR'03), 2003, Benevento, Italy, p. 91–100.
    10. 10)
      • J. Kerievsky . (2004) Refactoring to patterns.
    11. 11)
      • B. Kernighan , D. Ritchie . (1978) The C programming language.
    12. 12)
      • Counsell, S., Hassoun, Y., Johnson, R., Mannock, K., Mendes, E.: `Trends in Java code changes: the key identification of refactorings', Proc. ACM Int. Conf. on Principles and Practice of Programming in Java, 2003, Kilkenny, Ireland, p. 3–6.
    13. 13)
      • Counsell, S., Loizou, G., Najjar, R., Mannock, K.: `On the relationship between encapsulation, inheritance and friends in C++ software', Proc. Int. Conf. on Software System Engineering and its Applications (ICSSEA'02), 2002, Paris, France.
    14. 14)
      • Opdyke, W.: `Refactoring object-oriented frameworks', 1992, PhD, University of Illinois.
    15. 15)
      • Advani, D., Hassoun, Y., Counsell, S.: `Extracting refactoring trends from open-source software and a possible solution to the “related refactoring” conundrum', Proc. ACM Symp. on Applied Computing, 2006, Dijon, France, p. 1713–1720.
    16. 16)
      • Mantyla, M., Vanhanen, J., Lassenius, C.: `Bad smells – humans as code critics', Proc. IEEE Int. Conf. on Software Maintenance (ICSM'04), 2004, Chicago, USA, p. 399–408.
    17. 17)
      • Demeyer, S., Ducasse, S., Nierstrasz, O.: `Finding refactorings via change metrics', Proc. ACM Conf. on Object-Oriented Programming Systems, Languages and Applications (OOPSLA), Minneapolis, USA, p. 166–177.
    18. 18)
      • L. Tokuda , D. Batory . Evolving object-oriented designs with refactorings. Autom. Softw. Engng. , 89 - 120
    19. 19)
      • Najjar, R., Counsell, S., Loizou, G.: `Encapsulation and the vagaries of a simple refactoring: an empirical study', Technical Report, BBKCS-05-03-02, 2005, SCSIS-Birkbeck, University of London.
    20. 20)
      • W. Brown , R. Malveau , R. McCormick , T. Mowbray . (1998) AntiPatterns: refactoring software, architectures, and projects in crisis.
    21. 21)
      • L. Briand , J. Daly , J. Wust . A unified framework for cohesion measurement in object-oriented systems. Empir. Softw. Engng. , 1 , 65 - 117
    22. 22)
      • J. Bansiya , L. Etzkorn , C. Davis , W. Li . A class cohesion metric for object-oriented designs. J. Object-Oriented Program. , 8 , 47 - 52
    23. 23)
      • Najjar, R., Counsell, S., Loizou, G., Mannock, K.: `The role of constructors in the context of refactoring object-oriented software', Proc. European Conf. on Software Maintenance and Reengineering (CSMR'03), 2003, Benevento, Italy, p. 111–120.
    24. 24)
      • L. Briand , C. Bunse , J. Daly . A controlled experiment for evaluating quality guidelines on the maintainability of object-oriented designs. IEEE Trans. Softw. Engng. , 6 , 513 - 530
    25. 25)
      • Briand, L., Devanbu, P., Melo, W.: `An investigation into coupling measures for C++', Proc. Int. Conf. on Software Engineering (ICSE'97), 1997, Boston, USA, p. 412–421.
    26. 26)
      • K. El Emam , S. Benlarbi , N. Goel , S. Rai . The confounding effect of class size on the validity of object-oriented metrics. IEEE Trans. Softw. Engng. , 7 , 630 - 650
    27. 27)
      • R. Harrison , S. Counsell , R. Nithi . Experimental assessment of the effect of inheritance on the maintainability of object-oriented systems. J. Syst. Softw. , 1 , 173 - 179
    28. 28)
      • Harrison, R., Counsell, S., Nithi, R.: `Coupling metrics for OO design', Proc. IEEE Int. Symp. on Software Metrics, 1998, Bethesda, Maryland, USA, p. 150–157.
    29. 29)
      • J. Rumbaugh , I. Jacobson , G. Booch . (1998) The unified modeling language reference manual.
    30. 30)
      • S. Counsell , G. Loizou , R. Najjar . Quality of manual data collection in Java software: an empirical investigation. Empir. Softw. Engng. , 3 , 275 - 293
    31. 31)
      • Najjar, R.: `An empirical study on encapsulation and refactoring in the object-oriented paradigm', 2008, PhD, Birkbeck, University of London, UK.
    32. 32)
      • Hamza, H., Counsell, S., Hall, T., Loizou, G.: `Code smell eradication and associated refactoring', Proc. European Computing Conf., September 2008, Malta, p. 102–107.
    33. 33)
      • Rosenberg, J.: `Some misconceptions about lines of code', Proc. Int. Software Metrics Symp., 1997, Albuquerque, New Mexico, USA, p. 137–142.
    34. 34)
      • Ostrand, T., Weyuker, E., Bell, R.: `Where the bugs are', Proc. ACM SIGSOFT Int. Symp. on Software Testing and Analysis, 2004, Boston, MA, USA, p. 86–96.
    35. 35)
      • B. Henderson-Sellers , L. Constantine , I. Graham . Coupling and cohesion (towards a valid metrics suite for object-oriented analysis and design). Object-Oriented Syst. , 3 , 143 - 158
    36. 36)
      • Perry, D.: `Laws and principles of evolution, Panel Paper', Proc. Int. Conf. on Software Maintenance, 2002, Montreal, Canada, p. 70–71.
    37. 37)
      • A. Field . (2005) Discovering statistics using SPSS.
    38. 38)
      • Counsell, S., Hassoun, Y., Loizou, G., Najjar, R.: `Common refactorings, a dependency graph and some code smells: an empirical study of Java OSS', Proc. ACM/IEEE Int. Symp. on Empirical Software Engineering, 2006, Rio de Janeiro, Brazil, p. 288–296.
    39. 39)
      • S. Counsell , P. Newson . Use of friends in C++ software: an empirical investigation. J. Syst. Softw. , 1 , 15 - 21

Related content

This is a required field
Please enter a valid email address