Refactoring techniques

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.

Composing methods

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 ...

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.