AN AUTOMATED REFACTORING APPROACH TO DESIGN PATTERN-BASED PROGRAM TRANSFORMATIONS IN JAVA PROGRAMS Sang-Uk Jeon, Joon-Sang Lee, and Doo-Hwan Bae Division of Computer Science Department of Electrical Engineering and Computer Science Korea Advanced Institute of Science and Technology sujeon, joon, bae @se.kaist.ac.kr ABSTRACT Software often needs to be modified for accommodating re- quirements changes through the software life cycle. To deal with several accidental requirements changes related to soft- ware maintenance, a systematic and safe approach to mod- ifying softwares is needed. The design patterns provide a high degree of design flexibility for such accidental require- ments changes. In this paper, we propose an automated ap- proach to refactoring based on design patterns in Java pro- grams. In our approach, for a particular design pattern, we define an inference rule to automatically identify a set of candidate spots and a refactoring strategy to transform one of the set of candidate spots into the desired design pattern structure. A candidate spot may be a class or a set of classes to which the design patterns can be applied. We believe that our approach would be helpful to the maintainers in the sense that much of manual analysis on source code can be reduced, and the fashion of automated program transfor- mation preserves the behavior of the original program by means of the refactoring technique. 1. INTRODUCTION Through the software life cycle, most of the developed soft- ware systems need to be modified for accommodating re- quirements changes, or their program modules must be ap- propriately adapted so as to be reused in other application contexts. Very often, this kind of maintenance activities requires a very high cost effort, in the sense that the pro- gram modules expensively certified through robust verifica- tion and testing activities must be certified again against the changes to the software system, and such activities continue to occur until its retirement. To cope with such problems related to software maintenance, we need a systematic and safe approach to modifying the software system, which may be either of a running one or legacy one. Refactoring [1] is a safe program restructuring technique that can guarantee the restructured program to preserve the behavior of the original program. Various refactoring tech- niques have been proposed to modify the software structure which can be represented in the class diagram of UML, and also to transform the program in an automated way based on some quantitative metric or static analysis on the source code. In common, a refactoring technique provides a set of primitive refactoring operations, and allows such primi- tive operations to be sequentially and combinatorially com- posed into a high-level refactoring rule, which may involve several software quality issues such as higher modularity, performance improvement, lower code redundancy, and so on. Design patterns [3] are a collection of recurring patterns of relationships among classes, objects, methods, etc. Each design pattern describes its own application area, structure / behavior pattern, and rationale. Thus, the rationale and application area can be used as a good goal for high-level refactoring. The design patterns are widely used because they provide design-level reusability, understandability, and flexibility. Especially, the flexibility affords to be focused on in the sense that the program can be formed more open- ended and less sensitive to the requirements change. Many prior approaches to automated introduction of the design patterns have focused on only how to transform a given software system into a new one which have certain desired design pattern by applying a sequence of primitive refactoring operations defined for class-structure transfor- mation [7, 9, 11]. In other words, there has been no ap- proach to automatically recognizing a set of candidate spots where to apply some design pattern-based refactoring in the source code. After inspecting a target source code suffi- ciently, the designer can decide what design pattern could be applied to which spot, then a tool helps the program transformation automatically. The tool only helps tedious modifications. If the size of source code is very huge, even if worse, there is no related document, it becomes extremely difficult to inspect all of the source code for understanding in detail. Therefore, the automated and systematic way of identifying candidate spots in which a certain design pattern