Original article: Refactoring: Decompose Conditional
All languages and programming styles, but usually more applicable for imperative langauges.
Usually results in longer code but with much better readability.
if (date.before (SUMMER_START) || date.after(SUMMER_END)) | |
charge = quantity * _winterRate + _winterServiceCharge; | |
else | |
charge = quantity * _summerRate; |
if (notSummer(date)) | |
charge = winterCharge(quantity); | |
else | |
charge = summerCharge (quantity); | |
// helpers | |
function notSummer(date) { | |
return date.before(SUMMER_START) || date.after(SUMMER_END); | |
} | |
function winterCharge(q) { | |
return q * _winterRate + _winterServiceCharge | |
} | |
function summerCharge(q) { | |
return q * _summerRate; | |
} |
Original article: Refactoring: Decompose Conditional
All languages and programming styles, but usually more applicable for imperative langauges.
Usually results in longer code but with much better readability.