Automated and Manual Refactorings
Explore automated and manual refactoring methods to improve Java code clarity and maintainability while using JUnit tests to ensure functionality remains intact. Understand the importance of careful refactoring and how IDE tools can assist the process. Practice restructuring methods and running tests to verify correct behavior after changes.
We'll cover the following...
Refactoring code is always a delicate task which can lead to a bigger misunderstanding if not done carefully.
In our case, the answer local variable doesn’t clarify the code, and it’s used only once. Inline (remove) the variable by replacing its use with the answerMatching(criterion) expression (line 2) in Profile.java:
Automatic Refactoring
We could manually inline answer, but our IDE will most likely automate the inline refactoring. In Eclipse, select Refactor ▶ Inline from the main menu to inline.
The very existence of automated IDE should reinforce that ...