-
(스프링 기본) 5 - 객체 지향 설계와 스프링개발/Spring 2024. 10. 2. 23:00
■ 스프링에서 왜 객체 지향 이야기가 나올까?
- 스프링은 아래 기술로 다형성 + OCP, DIP 를 가능하게 지원
> DI(Dependency Injection) : 의존관계, 의존성 주입
> DI 컨테이너 제공 : 자바 객체를 컨테이너에 넣고 그 안에서 의존관계를 주입시킴
- 클라이언트 코드의 변경 없이 기능 확장
- 쉽게 부품 교체하든 개발 가능
■ 스프링 없었을 때
- 좋은 객체 개발을 하려고 OCP, DIP 원칙 지키려고 하다 보니 할 일이 많아짐
> 프레임워크로 만들어버림
- 순수 자바 개발을 하면, 결국 스프링 프레임 워크를 만들게 된다. (정확히는 DI 컨테이너)
■ 정리
- 모든 설계에 역할과 구현 분리하자
ex) 자동차, 공연
- 애플리케이션 설계도 공연을 설계 하듯이 배역만 만들어두고,
배우는 유연하게 변경할 수 있도록 만드는 것이 좋은 객체 지향 설계이다.
- 이상적으로 모든 설계에 인터페이스를 부여하자
(실무문제)
- 인터페이스를 도입하면 추상화라는 비용이 발생한다.
- 기능을 확장할 가능성이 없다면, 구체 클래스 직접 사용
향후 꼭 필요할 때 리팩터링해서 인터페이스를 도입하는 것도 방법이다.
'개발 > Spring' 카테고리의 다른 글