4주차: 7장 캡슐화 #8
Replies: 7 comments
-
캡슐화가 모두 능사는 아니다. 캡슐화를 했다가도 다시 인라인하거나 중개자를 제거할 수 있어야 한다. |
Beta Was this translation helpful? Give feedback.
-
컬렉션을 다룰 때 주의 깊게 다뤄야 한다는 것을 다시 리마인드했습니다. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
7.6장 클래스 인라인하기(Inline Class) 예시를 이해하기 어려웠습니다. (리팩터링 하기전) TrackingInformation 클래스의 display메서드명을 trackingInfo로 바꾼게 끝이 아닌가 싶었습니다. 리팩터링 전// Address.js
class Address {
constructor(street, city) {
this.street = street;
this.city = city;
}
getFullAddress() {
return `${this.street}, ${this.city}`;
}
}
export default Address;
// Person.js
import Address from './Address';
class Person {
constructor(name, street, city) {
this.name = name;
this.address = new Address(street, city);
}
getDetails() {
return `${this.name} lives at ${this.address.getFullAddress()}`;
}
}
export default Person; 리팩터링 후Address 클래스를 Person 클래스에 통합하여 인라인합니다. // Person.js
class Person {
constructor(name, street, city) {
this.name = name;
this.street = street;
this.city = city;
}
getFullAddress() {
return `${this.street}, ${this.city}`;
}
getDetails() {
return `${this.name} lives at ${this.getFullAddress()}`;
}
}
export default Person; 이렇게 클래스를 인라인하면 코드의 복잡성을 줄이고, 관련된 기능을 한 곳에 모아 유지보수를 쉽게 할 수 있�다. 클래스를 안써봐서 소스 클래스? 타깃 클래스? 위임 메서드? 용어를 이해하지 못했는데, |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
const getIsToday = (deadline: string): boolean => {
/* ... */
} const getIsCurrentWeek = (dateString: string): boolean => {
/* ... */
} 위와 같이 동일한 API로부터 받아온 값들임에도 따로 유틸함수로만 관리하고 있어 코드의 응집도가 떨어졌다는 것을 알 수 있었습니다. 특정 데이터에서 여러 기능이 필요할 때 클래스를 활용해봐야겠습니다.
getPrize() {
/* ... */
return this.#prize;
} 객체의 경우 |
Beta Was this translation helpful? Give feedback.
-
7.5 클래스 추출하기를 거꾸로 돌리는 7.6 클래스 인라인하기가 인상 깊었습니다. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
인상깊었던 책의 내용과 인상깊었던 이유
현업 등 코드에 반영할 수 있는 방법과 생각
관련 아티클이나 이해를 돕는 자료를 첨부
새롭게 알게된 점이나 이해가 어려웠던 점
Beta Was this translation helpful? Give feedback.
All reactions