Introduce Parameter Object - Refactoring skills(8)
8. Introduce Parameter Object(매개변수 객체 만들기)
Replace groups of data items that regularly travel together with a single data structure
(산재 되어있는 데이터 항목들을 하나의 데이터 객체로 구조화)
function amountInvoiced(startDate, endDate) {}
function amountReceived(startDate, endDate) {}
function amountOverdue(startDate, endDate) {}
to
function amountInvoiced(aDateRange) {}
function amountReceived(aDateRange) {}
function amountOverdue(aDateRange) {}
Motivation
- Make explicit the relationship between the data items
데이터 항목간의 명확한 관계설정이 가능 - Reduce the size of parameter list
파라미터 갯수를 줄일 수 있다. - Make code more consistent
같은 데이터 구조를 사용하는 모든 함수가 원소를 참조할 때 항상 똑같은 이름을 사용하기 때문에 일관성도 높여준다. - Enable deeper changes to the code
리팩터링 할 시 코드를 더 근본적으로 바꿔준다.
Procedure
-
If there is no appropriate data structure, make new one.
적당한 데이터 구조가 아직 마련되어 있지 않다면 새로 만든다. -
Test it.
테스트한다. -
Add the new data structure with function name change
함수 선언 바꾸기로 새 데이터 구조를 매개변수로 추가한다. -
Test it.
테스트 -
Modify to pass a new data structure instance when calling a function. Test every modification.
함수 호출 시 새로운 데이터 구조 인스턴스를 넘기도록 수정한다. 하나씩 수정할 때마다 테스트한다. -
Replace previous parameters to new data structrue one.
기존 매개변수를 사용하던 코드를 새 데이터 구조의 원소를 사용하도록 바꾼다. -
If you finish to replace, remove previous parameters and test them.
다 바꿨다면 기존 매개변수를 제거하고 테스트한다.
Author And Source
이 문제에 관하여(Introduce Parameter Object - Refactoring skills(8)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kerem119/Introduce-Parameter-Object-Refactoring-skills8저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)