Post on 11-Jun-2015
Introduction to Refactoring
Step 1What, Why, When, How
bw.moon@lge.com
What is refactoring
• Fowler's definition “A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior”
Why
Bad Smell
Good Smell
When
Bad Smell
Iterative
Unit test
Unit
test
How : Extract
Extract Class
Extract Method
Remove
Remove Middle Man
Remove Setting Method
Replace
Replace Assignment with Initializa-tion
void foo() { int i; // .... i = 7; }
void foo() { // ... int i = 7; }
Replace Constructor with Factory Method
Employee (int type) { _type = type; }
static Employee create(int type) { re-turn new Employee(type); }
Hide
Hide Delegate
Hide Method
Resources 1
1 장 . 리팩토링 비디오 2 장 . 리팩토링의 원리 3 장 . 코드에서의 나쁜 냄새 4 장 . 테스트 만들기 5 장 . 리팩토링 카탈로그로 ... 6 장 . 메쏘드 구성 7 장 . 객체간의 기능 이동 8 장 . 데이터 구성 9 장 . 조건문의 단순화 10장 . 메쏘드 호출의 단순화 11장 . 일반화 다루기 12장 . 대규모 리팩토링 13장 . 리팩토링 재사용 , 그리고 현실 14장 . 리팩토링 도구 15장 . 모두 합치기
Resources 2• [ 항목 24] 컴파일 경고 메시지가 없게 하자 158• [ 항목 30] int 상수 대신 enum 을 사용하자 201• [ 항목 38] 매개 변수가 유효한지 검사하자 247• [ 항목 43] null 대신 비어있는 배열이나 컬렉션을 반환하자 274• [ 항목 45] 지역 변수의 유효 범위를 최소화 하자 285• [ 항목 47] 라이브러리를 배우고 사용하자 293• [ 항목 48] 정확한 계산에는 float 나 double 타입을 쓰지 말자
297• [ 항목 49] 박스화 기본형보다는 기본형을 사용하자 300• [ 항목 56] 보편화된 작명 규칙을 따르자 323• [ 항목 62] 메소드가 던지는 모든 예외를 문서화하자 344• [ 항목 63] 실패 상황 정보를 상세 메시지에 포함하자 346• [ 항목 64] 실패 원자성을 갖도록 노력하자 349
Q&A