A method has conditional behavior that does not make clear what the normal path of execution is
Use Guard Clauses for all the special cases
1 2 3 4 5 6 7 8 9 10 11 12
double getPayAmount() { double result; if (_isDead) result = deadAmount(); else { if (_isSeparated) result = separatedAmount(); else { if (_isRetired) result = retiredAmount(); else result = normalPayAmount(); }; } return result; };
1 2 3 4 5 6
double getPayAmount() { if (_isDead) return deadAmount(); if (_isSeparated) return separatedAmount(); if (_isRetired) return retiredAmount(); return normalPayAmount(); };
近期评论