Font Size: a A A

Java Program Refactoring Towards MVC Model

Posted on:2006-07-17Degree:MasterType:Thesis
Country:ChinaCandidate:S T LuoFull Text:PDF
GTID:2168360155952963Subject:Computer software and theory
Abstract/Summary:PDF Full Text Request
With the size of software system growing, the cost of maintenance for the system increases rapidly. In the phase of system design, it decreases the cost of maintenance greatly if structures with high quality characteristics are applied. MVC framework is one of the most effective alternatives of this kind of structures. MVC provides a way to carve up the system. By using MVC, a software system could be divided into three parts: input, output, and business management that correspond to controller, view and model. The purpose of MVC is to encapsulate code into modules and make the structure clear. But the ever-present of mixture of business management and view destroys the structure of MVC. Splitting the mixture of model and view results in great benefit for maintenance, and provides a foundation for code reuse. This paper mainly focuses on distinguishing business management from views in static view and encapsulating business management into individual model. The static view in this paper means the view that cannot be changed after coding. Since the swing component technique is often used to develop the part of view, our refactoring method is based on the programs of static view developed with swing component. It is supposed that the classes, interfaces and methods in the component of swing are all consistent with MVC. It is also supposed that the methods coded by programmer, which is called non-standard methods, is those that are not consistent with MVC. The model code is frequently mixed in those methods. Using class inheritance tree, all the classes of swing or classes inherited from swing are obtained and marked. Using class—method tree, all the methods in the marked classes are also obtained and marked. Through comparing the marked methods with those in standard classes of swing, the methods programmed by developer are found. To avoid making mistakes of structure, the methods obtained is processed one by one. In this paper, an approach of separating non-standard methods from the class of swing and encapsulating the methods into individual class without affecting the results of program is presented. The approach includes two steps: (1) separating non-standard methods from the class which they exist, hiding all the information of the methods being separated from the class; (2) encapsulating each separated methods, changing all the invocation information of the methods. In our approach, the found non-standard methods are separated from the class and moved into an individual encapsulation class. At the same time, all the definition statements are deleted from original classes. Considering the initialization and reference of variables, static variables and construct functions of origin class are also copied to encapsulation class while moving the methods. The invocation between methods, the invocation to method from objects and the overloading of the methods must be considered in the procedure of encapsulating the method into encapsulation class. Those relations make the movement of a method from a class to anther class very difficult. There are two kinds of the invocation between methods: invocation from a moved method to fixed method, invocation from fixed method to moved method. To solve the problem of invocation between methods, the relation of the methods must be analyzed to locate the class, which the invoked methods exist. The class name is added in front of the invoked method to make the compiler to locate the invoked methods exactly. To change the relation between object and the moved methods, a new encapsulation class's object must be defined to take place the original object. The problem of overload method is solved much easier than former problems. It is obvious that the overloaded method must be a non-standard method if the original method is a non-standard method. Therefore if a method is moved, the overload methods must be moved together. A method will be encapsulated into encapsulation class completely by changing the relations as mentioned above. At last, we develop a refactoring tool—JMVCRefining to introducing MVC. The tool achieves the refactoring goal and reveals the process of analysis. After optimizing a piece of code, feasibility of the refactoring approach is proved through comparing original code and refactored code.
Keywords/Search Tags:Refactoring
PDF Full Text Request
Related items