Overview of Refactoring Options
Method Extraction
One important refactoring technique is method extraction. This involves moving a code block to a new method and replacing the block with a call to that new method. To perform method extraction, you must be editing a global or local ABAP class in a class pool, a program, or another type of ABAP program. Your code must be free of syntax errors before you begin. Note that method extraction is not supported in code outside of classes and that you can only extract a method within the start and end area of another method.
The figure shows two methods of the same class. They both need the same existence check - although the processing that follows is different.
Extracting a Method: After
To increase coding reuse, you want to create a private method with the existence check, as shown in the figure.
ADT supports the creation of method, CHECK_EXISTENCE, and its call in one of the original methods by using the Extract Method function.
Deletion of Unused Variables
Another key refactoring technique is the deletion of the unused variables that can accumulate in code over time. For example, perhaps you no longer need the code associated with a variable and deleted the code but not the variable, or you may have extracted a method, leaving behind data declarations that are outside of the scope of the extracted code.
Source Code Entity Name Changes
In object-oriented programming, it sometimes becomes necessary to rename classes, interfaces, or any of their components. Adjusting the coding lines referencing the entity then becomes a tiresome and time-consuming process, particularly if the entity is globally visible and frequently reused. ADT allows you to rename the entity, and adjust all objects that use it.