Automated and Manual Refactorings
We will learn automated and manual refactoring to reduce the code junk overheard.
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
:
Press + to interact
for (Criterion criterion: criteria) {boolean match = criterion.matches(answerMatching(criterion));if (!match && criterion.getWeight() == Weight.MustMatch) {kill = true;}if (match) {score += criterion.getWeight().getValue();}anyMatches |= match;}
Automatic Refactoring
We could manually inline answer
, but our IDE will most likely automate the inline refactoring. In Eclipse, select Refactor ▶ Inline from the ...
Access this course and 1400+ top-rated courses and projects.