AppConfig 리팩토링
현재 AppConfig는 중복되는 부분이 있고, 역할에 따른 구현이 잘 안보인다.
코드를 수정해보자.
public class AppConfig {
public MemberService memberService() {
return new MemberServiceImpl(memberRepository());
}
private MemberRepository memberRepository() {
return new MemoryMemberRepository();
}
public OrderService orderService() {
return new OrderServiceImpl(memberRepository(), discountPolicy());
}
public DiscountPolicy discountPolicy() {
return new FixDiscountPolicy();
}
}
=> 메서드명을 보면 역할이 드러나도록 수정했다.
또한 나중에 memberRepository를 디비로 변경한다고 했을 때 한 부분만 수정하면된다.
* 인프런 '스프링 핵심 원리 -기본편' 강의를 참고하여 작성했습니다.
'웹 개발 > Spring' 카테고리의 다른 글
[Spring 기본] 좋은 객체 지향 설계의 5가지 원칙의 적용 (0) | 2024.08.13 |
---|---|
[Spring 기본] 새로운 구조와 할인 정책 적용 (0) | 2024.08.13 |
[Spring 기본] 관심사의 분리 (0) | 2024.08.13 |
[Spring 기본] 새로운 할인 정책 개발 (0) | 2024.08.12 |
[Spring 기본] 주문과 할인 도메인 개발 (0) | 2024.08.08 |