나 자신도 그렇고 다른 사람들한테 물어보면 아래와 같은 답들을 들을 수 있었다.
근데 대부분 아무 의미 없이 아래처럼 쓰이고 있다.
class MyClass {
private $firstField;
private $secondField;
public function getFirstField() {
return $this->firstField;
}
public function setFirstField($x) {
$this->firstField = $x;
}
public function getSecondField() {
return $this->secondField;
}
public function setSecondField($x) {
$this->secondField = $x;
}
}
심지어 구글도 추천하지 않는단다.
의미 없는 getter/setter 를 안쓰고 public 멤버변수로 접근하면 2배 빠르다고 소개하고 있다.
PHP performance tips - Make the Web Faster - Google Developers
그래서 시작된 getter/setter 의 필요성에 대한 조사를 시작했다.
그러다 찾게된 oop를 잘 모르는 사람도 납득시킬 만한 이유를 제시한 블로그의 글을 찾게 됐다.
그래!
이것으로 난 충분히 납득됐고, 이런 질문을 하는 다른 사람도 납득 시킬 수 있을꺼 같았다.