Refactoring Games : 15 things to do after extracting a method with Java


Details
In our quest against increasing complexity, Extract Method is probably the most important refactoring technique in our hands. We use it a dozen times per day as a first-level weapon, and very often it leads to us to deeper design insights. Let’s look at several such further actions you might take after pulling some code out in a separate method:
Reorder Parameters
Remove parameters by including more lines in what you extract (Ctrl-Z)
Add parameters for reuse by extract/inline variable at call site (Ctrl-Z)
Move method to object (for Feature Envy)
Encapsulate conditionals (great with Java8)
Introduce Strategy Pattern for alternative large logic
Distill switch expressions
Introduce Method Object for heavy logic
Early return errors
Extract static util functions
Spawn smart Value Object vs logic in Utils
Extract’n-test then mock away, leading to Separation by Layers of Abstraction
Command-Query Separation: mind the side effects
Extract again - boolean vs SRP
Wrap call to safely add more code (Open-Closed)
Bio:
Victor Rentea is a Java Champion, former Lead Architect at IBM, and the founder of Bucharest Software Craftsmanship Community in which he spreads the word about simple design, refactoring, and unit testing. He earns a living as a full-time trainer and consultant, working each week with teams in dozens of companies throughout the world. He constantly shares his passion in community talks (remote streamed these days) and conference talks. You can find him on Twitter, Facebook or LinkedIn as well as on his Teachable school.

Refactoring Games : 15 things to do after extracting a method with Java