-
메소드 정리 : Split Temporary VariableProgramming/리팩토링 2020. 9. 4. 16:10
참고자료
http://refactoring.guru/split-temporary-variable
Split Temporary Variable
Tired of reading? No wonder, it takes 7 hours to read all of the text we have here. Try our interactive course on refactoring. It offers a less tedious approach to learning new stuff. Let's see...
refactoring.guru
정의
함수 안에서 지역변수로 만들어진 임시변수가 여러번 할당하는 경우, 각각의 할당에 대해서 임시변수를 만들어 가독성을 올린다.
기존 예시
// Example Code double temp = 2 * (height + width); System.out.println(temp); temp = height * width;
temp가 할당이 되어 여러번 바뀌게 되는 것을 리펙토링한다.
리팩토링 예시
double perimeter = 2 * (height + width); System.out.println(perimeter); double area = height * width; System.out.println(area);
반응형'Programming > 리팩토링' 카테고리의 다른 글
메소드 정리 : Replace Method with Method Object (0) 2020.09.04 메소드 정리 : Remove Assignments to Parameters (0) 2020.09.04 메소드 정리 : Replace Temp with Query (0) 2020.09.04 메소드 정리 : Inline Temp (0) 2020.09.04 메소드 정리 : Inline Method (0) 2020.09.04