Combine Functions Into Class - Refactoring skills(9)

Kerem Song·2021년 3월 23일
0

Refactoring - Study

목록 보기
11/22

9. Combine Functions Into Class(함수들을 클래스로 병합하기)

Form a class base on group of functions that operate closely on a common data
(공통 데이터를 중심으로 작동하는 함수들을 발견할 시 클래스 하나로 묶기)

function base(aReading) {}
function taxableCharge(aReading) {}
function calculateBaseCharge(aReading) {}

to

class Reading() {
  base() {}
  taxableCharge() {}
  calculateBaseCharge() {}
}

Motivation

  1. Simplify function call by removing many arguments
    각 함수에 전달되는 인수를 줄여서 객체안에서의 함수 호출을 간결하게 만들 수 있다.
  2. Easier to pass object to other parts of the system
    객체를 시스템의 다른 부분에 전달하기 위한 참조를 제공할 수 있다.

Procedure

  1. Encapsulate common data shared by functions.
    함수들이 공유하는 공통 데이터 레코드를 캡슐화한다.

  2. Move functions using common data to a new class
    공통 레코드를 사용하는 함수 각각을 새 클래스로 옮긴다.(함수 옮기기)

  3. Logic manipulating data is extracted as a function and transferred to a new class
    데이터를 조작하는 로직들은 함수로 추출해서 새 클래스로 옮긴다.

profile
Tea and Dessert

0개의 댓글