Open
Description
See this problem: https://refactoring.guru/consolidate-duplicate-conditional-fragments
The problematic code is:
if (isSpecialDeal()) {
total = price * 0.95;
send();
}
else {
total = price * 0.98;
send();
}
The proposed solution is:
if (isSpecialDeal()) {
total = price * 0.95;
}
else {
total = price * 0.98;
}
send();
yet it still duplicates the logic of calculating the total.
A better solution would be something like this:
total = price * (isSpecialDeal() ? 0.95 : 0.98);
send();
Metadata
Metadata
Assignees
Labels
No labels