데이터 구성

컴투루·2022년 4월 15일
0

📌 필드 자체 캡슐화 (Self Encapsulate Field)

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/

profile
맘 먹으면 못할 게 없지

0개의 댓글