-
리팩토링 : Replace Error Code with Exception리팩토링 2013. 2. 5. 09:00조건메소드가 에러대신에 특정 코드를 반환한다면적용대신에 예외를 던지시오.적용전
int withdraw(int amount) { if (amount > _balance) return -1; else { _balance -= amount; return 0; } }
적용후void withdraw(int amount) throws BalanceException { if (amount > _balance) throw new BalanceException(); _balance -= amount; }
참조'리팩토링' 카테고리의 다른 글
리팩토링 : Replace Inheritance with Delegation (0) 2013.02.07 리팩토링 : Replace Exception with Test (0) 2013.02.06 리팩토링 : Replace Delegation with Inheritance (0) 2013.02.04 리팩토링 : Replace Data Value with Object (0) 2013.02.03 리팩토링 : Replace Constructor with Factory Method (0) 2013.02.02 댓글