-
객체 간 기능 이동 : Extract Class, Inline ClassProgramming/리팩토링 2020. 9. 5. 19:07
참고자료
https://refactoring.guru/extract-class
Extract Class
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
https://refactoring.guru/inline-class
Inline Class
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
Extract Class 정의
두개의 클래스의 일을 한개의 클래스가 하고 있을 때, 새로운 클래스를 만들고 관련 있는 필드와 함수를 이전 클래스에서 새로운 클래스로 옮기는 기법
예시
class Person { private: char name[10]; int areaOfficeCode; int officeNumber; public: int getTelephoneNumber(); }
리팩토링 예시
class Person { private: char name[10]; public: int getTelephoneNumber(); } class TelephoneNumber { private: int areaOfficeNumber; int officeNumber; public: int getTelephoneNumber(); }
Inline Class 정의
클래스가 하는 일이 많지 않은 경우, 해당 클래스에 있는 모든 변수와 함수를 다른 클래스로 옮기고 그 클래스를 제거하는 기법.
위의 리팩토리 예시를 기존 예시로 바꾸면 된다. 반대 개념으로 알고 있자
반응형'Programming > 리팩토링' 카테고리의 다른 글
데이터 구성 : Self Encapsulate Field (0) 2020.09.06 객체 간 기능 이동 : Introduce Foreign Method, Introduce Local Extension (0) 2020.09.06 객체 간 기능 이동 : Move Method, Move Field (0) 2020.09.05 메소드 정리 : Replace Method with Method Object (0) 2020.09.04 메소드 정리 : Remove Assignments to Parameters (0) 2020.09.04