✏️10.2 조건식 통합하기 (Consolidate Conditional Expression)
if (anEmployee.seniority < 2) return 0;
if (anEmployee.monthsDisabled > 12) return 0;
if (anEmployee.isPartTime) return 0;if (isNotEligableForDisability()) return 0;
function isNotEligableForDisability() {
return ((anEmployee.seniority < 2)
|| (anEmployee.monthsDisabled > 12)
|| (anEmployee.isPartTime));
}🧷 배경
🧷 절차
🧷 예시: or 사용하기
🧷 리팩터링 전
🧷 리팩터링 후
🧷 예시: and 사용하기
🧷 리팩터링 전
🧷 리팩터링 후
Previous10.1 조건문 분해하기 (Decompose Conditional)Next10.3 중첩 조건문을 보호 구문으로 바꾸기 (Replace Nested Conditional with Guard Clauses)
Last updated