posts/2019/aws-also-doesnt-use-setters/ #129
Replies: 2 comments
-
Boot + JPA 프로젝트 진행하면서 Setter와 Getter에 대해 고민하던 중에 좋은 글을 발견하게 되었네요! 감사합니다.
|
Beta Was this translation helpful? Give feedback.
-
안녕하세요. 부족한 글임에도 시간 내어 읽어주셔서 감사합니다. :) getter 역시 객체지향의 메시지 관점에서 지양하는 것이 좋다고 생각합니다. 예를 들어 어떤 시스템에서 A 객체가 B 객체의 만료 여부를 확인하기 위해 B 객체의 만료 시각 데이터를 getter를 통해 얻어와 검증하고 있다고 가정해 볼게요. 이 상황에서 새로운 요구사항이 들어왔고 이로 인해 C 객체도 B 객체의 만료 여부를 확인할 필요가 생겼습니다. 현재 B 객체에는 만료 여부를 반환하는 인터페이스가 없으므로 결국 C 객체도 B 객체의 getter를 통해 만료 시각 데이터를 얻어와 만료 여부를 연산하게 될 텐데요. 이때 A와 C는 동일한 코드를 중복해서 작성하게 됩니다. 이렇게 코드가 중복된 이유는 B가 스스로 제공할 수 있는 정보를 외부에서 처리하였기 때문입니다. B 객체 스스로 자신이 현재 유효한 상태인지 반환하는 인터페이스를 제공했다면 이러한 문제는 발생하지 않았을 것입니다. 도움이 되셨으면 좋겠습니다. 감사합니다.
|
Beta Was this translation helpful? Give feedback.
-
https://blog.sogoagain.com/posts/2019/aws-also-doesnt-use-setters/
Beta Was this translation helpful? Give feedback.
All reactions