exampleVariable
과 같은 변수를 가지고 있는데 getExampleVariable()
과 setExampleVariable(Object value)
을 사용해야하고 ExampleClass.exampleVariable
과 ExampleClass.exampleVariable = exampleObject;
대신 exampleVariable
을 비공개로 설정해야하나요?getter 및 setter를 언제 사용합니까?
나는 getter와 setter가 변수를 설정하는 것 이상을하지 않더라도 항상 getter와 setter를 사용합니다.
예. 캡슐화는이 원칙을 지시합니다. – Dan
[Pick] (http://stackoverflow.com/questions/565095/are-getters-and-setters-evil?rq = 1) [and] (http://stackoverflow.com/questions/875033/getters-setters-in-java?rq=1) [선택] (http://stackoverflow.com/questions/875033/getters- setters-in-java? rq = 1) [a] (http://stackoverflow.com/questions/10407877/what-is-the-point-of-getters-and-setters?lq=1) [duplicate] (http://stackoverflow.com/questions/1461598/what-is-the-point-of-setters-and-getters-in-java?lq=1) [질문] (http://stackoverflow.com/questions/) 11883454/필요성 - getter-methods? lq = 1)! – eboix
@ Dan 비록 일부는이 원칙을 "정보 은닉"이라고 부릅니다. – Scooter