4.3.4 Other transformations, Wizards

 

There are a large number of additional refactorings which can be added to the 30 transformations described above. Many of those additional transformations can be composed by using existing refactorings(see section 4.4)

 

The transformations described in this chapter have a "human"-character. Programmers are humans and once they have seen a generated comment they don't want to see it again! It is important to create comments when a code-generator modifies the code of the program, but it is nice to have a wizard which will remove those comments. Some of the lazy programmers will be happy to see transformations which will create access-methods for class private variables.

An other nice feature of a good transformation tool is the Class-Browser, so that some of vi-developed programs can be easy browsed by the programmer.  

 

4.3.4.1 Variable-access transformation

 

Description:   Transformation creates Get/Set- Methods for a variable.

Conditions:    Variable exists in class.

DPT:              DPT checks the condition.

Parameters:    String (full variable name)

Output:          String (variable name). Output can be used in composite-transformation.

Program:        New methods will be added. Behavior does not change.

 

Note: The method-names will be generated by transformation (Get/Set + variable name) If name already exists DPT will notify user. 

 

 

4.3.4.2 Remove comments wizard

 

Description: This wizard removes generator created comments from the code.

Parameters:    String (full file name)

Program:        Behavior does not change.

 

4.3.4.3 Class Browser wizard

 

Description:   This wizard returns the program code location of the symbol.

Parameters:    String (full symbol name)

Program:        Behavior does not change.

 

4.4 Composed refactorings

 

Standard refactoring transformations described above give a good base to develop new, more complex and powerful transformations as a composition of many simple operations. A good tool should give programmers possibilities to compose their own transformations.

 

4.4.1 Transformations for design pattern

 

A composed transformation can be used especially to support a design pattern transformation. Program transformations described in section 2.2 realized the „Abstract factory“-pattern  refactoring. These can be stored as composed transformations and applied to other projects.

 

(Figure 4.9 GUI: DPT-Dialog „Composite“)

 

4.4.2 Mechanism of composition

 

DPT offers the possibility to composite new transformations. The following mechanism is used to compose transformations from pre-existing. (Note: Each transformation is a java -bean with the same interface.)

 

1) User creates transformations from the list of available transformations

 - DPT checks that the output-type of the current bean is equal to the input parameter(s)

            of the next bean in the sequence of selected beans

 - The names of the component-beans will be stored in a vector and saved to a file

 - If a selected transformation is already a composed transformation, it will be resolved.

 

2) User executes composed transformation:

    -      DPT reads the stored composition-file and loads all defined beans in a vector

            (this vector is an object with the same interface as the implemented bean)

   -       DPT handles this object as usual bean.

(Inside: Object executes each of the loaded beans and forwards the output parameters to

 the next bean in the sequence. The next bean sets those parameters and so on...)

 

4.4.3 Examples for composed transformations

 

- Description: Creates class-variable(type = interface) with concrete constructor : 

1) NewVariable (see section 4.3.1.1.3)            

2) SubstituteVariable (see section 4.3.2.2.1)

Creates new variable with initialization(via new)and substitutes type to it’s super-class

 

- Description: Creates Subclass and overwrite the methods of its super-class: 

1)  Specialize (see section 4.3.2.1.2)      

2) CopySetMethods (see section 4.3.1.1.2)

Creates new subclass for existing class and copies super-class methods to new subclass.

See also figure 5.3 and figure 5.4 in chapter five.