Encapsulation(8) - Remove Middle Man

Kerem Song·2021년 4월 6일
0

Refactoring - Study

목록 보기
21/22

Remove Middle Man

(중간자 삭제)
Client call the delegate directly
(클라이언트가 위임을 바로 호출하게 한다.)

manager = aPerson.manager

class Person {
  get manager() {
    return this.department.manager
  }
}

to

manager = aPerson.department.manager

Motivation

  1. When there are too many delegating methods
    너무 많은 위임메소드가 있을때 용이하다

Procedure

  1. Make the getter which get the delegation object.
    위임 객체를 얻는 게터를 만든다.

  2. Modify all clients calling the delegation method to go through this getter. Test each time you change one by one.
    위임 메소드를 호출하는 클라이언트가 모두 이 게터를 거치도록 수정한다. 하나씩 바꿀 때마다 테스트한다.

  3. If you modify all, remove the delegation method
    모두 수정했다면 위임 메소드를 삭제한다.

profile
Tea and Dessert

0개의 댓글