(위임 제거하기)
A client is calling a delegate class of an object, create methods on the server to hide the delegate.
(클라이언트가 겍체의 위임 클래스를 호출한다. 서버에 위임을 숨길 메서드를 만든다.)
manager = aPerson.department.manager
to
manager = aPerson.manager
class Person {
get manager() {
return this.department.manager
}
}
Motivation
Client doesn't need to know and response to delegation's change
클라이언트는 위임이 변화에 책임지거나 알 필요가 없다.
Better encapsulation
캡슐화하기에 용이하다.
Procedure
1. Create a delegation method on the server that corresponds to each method of the delegation object.
위임 객체의 각 메소드에 해당하는 위임 메소드를 서버에 생성한다.
Modify that client should call the server instead of delegation object. Test it when you replace each part.
클라이언트가 위임 객체 대신 서버를 호출하도록 수정한다. 하나씩 바꿀 때마다 테스트한다.
If you modified all, remove the accessor which gets the delegation object from the server
모두 수정했다면, 서버로부터 위임 객체를 얻는 접근자를 제거한다.
Test it.
테스트한다.