태그를 입력해 주세요.
-
리팩토링 : Replace Parameter with Method리팩토링 2013. 2. 13. 09:00
조건객체가 메소드를 호출하고, 결과를 다른 메소드에 대한 파라메터로 반환하고,수신자가 또한 이 메소드를 호출한다면. 적용그 파라메터를 제거하고 수신자가 메소드를 호출하도록 만드시오. 적용전 int basePrice = _quantity * _itemPrice; discountLevel = getDiscountLevel(); double finalPrice = discountedPrice (basePrice, discountLevel); 적용후 int basePrice = _quantity * _itemPrice; double finalPrice = discountedPrice (basePrice); 참조http://www.refactoring.com/catalog/replaceParameterWithMe..
-
리팩토링 : 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; } 참조http://www.refactoring.com/catalog/replaceErrorCodeWithException.html
-
리팩토링 : Replace Constructor with Factory Method리팩토링 2013. 2. 2. 22:30
조건객체를 생성할때 간단한 생성자 이외의 것을 원한다면 적용생성자말고 팩토리(factory) 메소드를 이용하시오. 적용전 Employee (int type) { _type = type; } 적용후 static Employee create(int type) { return new Employee(type); } 참조http://www.refactoring.com/catalog/replaceConstructorWithFactoryMethod.html
-
리팩토링 : Inline Method리팩토링 2012. 12. 26. 09:00
조건메소드의 본문이 메소드 이름 만큼이나 명확하다면 적용해당 본문을 메소드를 호출하는 호출자 안으로 옮기고 메소드를 삭제하시오. 적용전 int getRating() { return (moreThanFiveLateDeliveries()) ? 2 : 1; } boolean moreThanFiveLateDeliveries() { return _numberOfLateDeliveries > 5; } 적용후 int getRating() { return (_numberOfLateDeliveries > 5) ? 2 : 1; } 참조http://www.refactoring.com/catalog/inlineMethod.html