Refactoring as formal refinements

Program restructuring in the context of object-oriented programming is known as refactoring. This consists of changes made to the internal structure of software in order to improve its legibility and make it easier to modify without changing its external behaviour. In practice, refactoring usually relies on compilation and tests in order to guarantee behaviour preservation. Works like those by Opdyke and Roberts have already been done in the direction of refactoring formalisation by means of the identification of conditions that must be satisfied to guarantee that a change to a program is behaviour preserving. The conditions, which are usually written in the predicate calculus, are introduced as preand postconditions of the refactorings. Other approaches for the proof of refactoring behaviour preservation use formalisms such as concept analysis and graph rewriting. However, there is no algebraic technique that presents refactorings as behaviour preserving transformations, with proofs carried out. This avoids changes of notation and facilitates mechanisation. Our contribution is to present refactorings as transformations of programs written in the language rool (Refinement object-oriented Language), which is a Java-like imperative language with classes, visibility control for attributes, dynamic binding, and recursion. It allows reasoning about object-oriented programs and specifications, as both kinds of constructs are mixed as in Morgan’s refinement calculus. The semantics of rool, as usual for refinement calculi, is based on weakest preconditions. A set of programming laws is available for the imperative constructs of rool as well as for its object-oriented features. The correctness of these laws, which is also a contribution of the present work, is proved against the semantics of rool. We present refactorings as algebraic refinement rules involving program terms. The proof that these rules are behaviour preserving is accomplished by the application of the programming laws of one of the sides of the rule to obtain the other side. The proofs of some refactoring rules also involve data refinement of classes. We generalise the standard data refinement technique from single modules (classes) to class hierarchies. Design patterns arise as a natural objective for refactoring a system. The literature on design patterns already presents works that propose the formalisation of design patterns. They usually concentrate on the formal description of patterns, not on the transformation of a system with the intention of obtaining a final system structure according to a design pattern. In this work, we also present how to obtain a system that is in accordance with design patterns by the application of refactoring rules proved to be behaviour preserving. We also present the transformation of a monolithic application to a well-structured one according to an architectural pattern.

[1]  Ivan Porres,et al.  Model Refactorings as Rule-Based Update Transformations , 2003, UML.

[2]  Don Roberts,et al.  Practical analysis for refactoring , 1999 .

[3]  Frank Tip,et al.  Refactoring for generalization using type constraints , 2003, OOPSLA 2003.

[4]  Tom Mens,et al.  A formal foundation for object-oriented software evolution , 2001, Proceedings IEEE International Conference on Software Maintenance. ICSM 2001.

[5]  Tom Mens,et al.  Formalising Behaviour Preserving Program Transformations , 2002, ICGT.

[6]  Don S. Batory,et al.  Evolving Object-Oriented Designs with Refactorings , 2004, Automated Software Engineering.

[7]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[8]  Barry Mark Utting An object-oriented refinement calculus with modular reasoning , 1992 .

[9]  J. Michael Spivey,et al.  The Z notation - a reference manual , 1992, Prentice Hall International Series in Computer Science.

[10]  Mary Shaw,et al.  Software architecture - perspectives on an emerging discipline , 1996 .

[11]  Jean-Marc Jézéquel,et al.  Refactoring UML Models , 2001, UML.

[12]  Jim Woodcock,et al.  ArcAngel: a Tactic Language for Refinement , 2003, Formal Aspects of Computing.

[13]  Graeme Smith,et al.  The object-Z specification language: version 1 , 1991 .

[14]  S. J. Goldsack,et al.  Formalising design patterns , 1996, FME 1996.

[15]  Augusto Sampaio,et al.  Automation of a Normal Form Reduction Strategy for Object-oriented Programming , 2002 .

[16]  Jim Woodcock,et al.  Using Z - specification, refinement, and proof , 1996, Prentice Hall international series in computer science.

[17]  Ana Cavalcanti,et al.  Modular Object-oriented Z Specifications , 1990, Z User Workshop.

[18]  Frank Tip,et al.  Reengineering class hierarchies using concept analysis , 1998, SIGSOFT '98/FSE-6.

[19]  K. Rustan M. Leino Recursive Object Types in a Logic of Object-Oriented Programs , 1998, Nord. J. Comput..

[20]  Arun Lakhotia,et al.  Restructuring programs by tucking statements into functions , 1998, Inf. Softw. Technol..

[21]  Frank Tip,et al.  A survey of program slicing techniques , 1994, J. Program. Lang..

[22]  J. Michael Spivey,et al.  Understanding Z : A specification language and its formal semantics , 1985, Cambridge tracts in theoretical computer science.

[23]  Simon J. Thompson Refactoring Functional Programs , 2004, Advanced Functional Programming.

[24]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[25]  Joseph M. Morris,et al.  A Theoretical Basis for Stepwise Refinement and the Programming Calculus , 1987, Sci. Comput. Program..

[26]  Karl J. Lieberherr,et al.  Assuring good style for object-oriented programs , 1989, IEEE Software.

[27]  Ian M. Holland,et al.  Object-oriented programming: an objective sense of style , 1988, OOPSLA 1988.

[28]  Carroll Morgan,et al.  Programming from specifications , 1990, Prentice Hall International Series in computer science.

[29]  Simon Thompson,et al.  A Case Study in Refactoring Functional Programs , 2003 .