-
메소드 정리 : Extract MethodProgramming/리팩토링 2020. 9. 4. 14:58
참고자료
https://refactoring.guru/refactoring/catalog
Catalog of Refactoring
Bloaters are code, methods and classes that have increased to such gargantuan proportions that they are hard to work with. Usually these smells do not crop up right away, rather they accumulate over time as the program evolves (and especially when nobody m
refactoring.guru
정의
그룹으로 함께 묶을 수 있는 코드 조각이 있으면, 코드의 목적이 잘 드러나도록 함수의 이름을 지어 별도의 함수로 뽑아내는 작업
가독성이 좋아지며 잘 쪼개져 있을 때, 다른 메소드에서 사용될 확률이 높아져 가독성이 좋아질 수 있다.
예시
// Example Code void printContents(String title, int age) { printTableHead(); System.out.println("title: " + title); System.out.println("age: " + age_; }
리팩토링 예시
// Refactoring Code void printContents(String title, int age) { printTableHead(); printContentsDetail(title, age); } void printContentsDetail(String title, int age) { System.out.println("title: " + title); System.out.println("age: " + age); }
반응형'Programming > 리팩토링' 카테고리의 다른 글
메소드 정리 : Remove Assignments to Parameters (0) 2020.09.04 메소드 정리 : Split Temporary Variable (0) 2020.09.04 메소드 정리 : Replace Temp with Query (0) 2020.09.04 메소드 정리 : Inline Temp (0) 2020.09.04 메소드 정리 : Inline Method (0) 2020.09.04