setter, getter 메서드를 작성해서 두 메서드를 통해서만 필드에 접근하도록 하는 기법
하위클래스가 메서드에 해당 정보를 가져오는 방식을 재정의하거나 데이터 관리에서 유연함을 가짐
class SomeClass{
constructor() {
this.low;
this.high;
}
}
class SomeClass{
constructor(low, high){
this._low = low;
this._high = high;
}
get low(){
return this._low;
}
set low(number){
this._low = number;
}
get high(){
return this._high;
}
set high(number){
this._high = number;
}
}
📑 References
https://armadillo-dev.github.io/book/refactoring-08-organizing-data/