-
리팩토링 : Replace Recursion with Iteration리팩토링 2013. 2. 15. 09:00
작자 : Ivan Mitrovic
조건
이해하기 어려운 재귀호출을 사용하는 코드가 있다면
적용
재귀호출을 반복구문으로 변경하시오.
적용전
public void countDown(int n) { if(n == 0) return; System.out.println(n + "..."); waitASecond(); countDown(n-1); }
적용후
public void countDown(int n) { while(n > 0) { System.out.println(n + "..."); waitASecond (); n -= 1; } }
참조
http://www.refactoring.com/catalog/replaceRecursionWithIteration.html
'리팩토링' 카테고리의 다른 글
리팩토링 : Replace Subclass with Fields (0) 2013.02.17 리팩토링 : Replace Static Variable with Parameter (0) 2013.02.16 리팩토링 : Replace Record with Data Class (0) 2013.02.14 리팩토링 : Replace Parameter with Method (0) 2013.02.13 리팩토링 : Replace Parameter with Explicit Methods (0) 2013.02.12 댓글