Though it's fair to say refactoring is more about common sense than a technique, there are still some very obvious refactoring techniques. The first step is to identify the code smell, which we covered in the previous section. The list is not exhaustive but just covers some frequently occurring pitfalls. Let's discuss the refactoring techniques that we can use to eliminate these code smells.
The majority of the code smells discussed earlier arise from within the method. The following refactoring techniques help to streamline the code and remove duplication:
Extract method: Whenever you see a code fragment that can be grouped together and/or does not belong in its current place, this code can be extracted into its own method.
Before refactoring:
def printReport() { printBanner() println("Next line of report") println("Another line of report") }
After refactoring:
def printReport...