목록BE/Spring (178)
오봉이와 함께하는 개발 블로그
AppConfig 리팩토링 현재 AppConfig는 중복이 있고, 역할에 따른 구현이 잘 안 보임 기대하는 그림 리팩토링 후 package hello.core; import hello.core.discount.DiscountPolicy; import hello.core.discount.FixDiscountPolicy; import hello.core.member.MemberSerivce; import hello.core.member.MemberServiceImpl; import hello.core.member.MemoryMemberRepository; import hello.core.order.OrderService; import hello.core.order.OrderServiceImpl; public..
관심사의 분리 본인의 역할을 수행하는 것에만 집중해야 한다 어떤 구현체가 선택되더라도 코드 변경 없이 실행할 수 있어야 한다. 이를 위해 중간에 연결할 수 있는 무언가가 필요하다! AppConfig 등장 앱의 전체 동작 방식을 구성(config)하기 위해 구현 객체를 생성하고, 연결하는 책임을 가지는 별도의 설정 클래스 package hello.core; import hello.core.discount.FixDiscountPolicy; import hello.core.member.MemberSerivce; import hello.core.member.MemberServiceImpl; import hello.core.member.MemoryMemberRepository; import hello.core.o..
새로운 할인 정책 기존 고정 1000원 할인에서 금액에 따라 10% 할인으로 변경 RateDiscountPolicy 추가 RateDiscountPolicy 코드 package hello.core.discount; import hello.core.member.Grade; import hello.core.member.Member; public class RateDiscountPolicy implements DiscountPolicy{ private int discountPercent = 10; @Override public int discount(Member member, int price) { if(member.getGrade() == Grade.VIP) { return price * discountPer..
주문과 할인 도메인 설계 주문과 할인 정책 회원은 상품을 주문할 수 있음 회원 등급에 따라 할인 정책 적용할 수 있음 할인 정책은 모든 VIP는 1000원을 할인해주는 고정 금액 할인을 적용(나중에 변경될 수 있다.) 할인 정책은 변경 가능성이 높음 최악의 경우 할인을 적용하지 않을 수 있다. 주문 도메인 협력, 역할, 책임 주문 생성 : 클라이언트는 주문 서비스에 주문 생성 요청 회원 조회 : 할인을 위해 회원등급 조회 할인 적용 : 회원 등급에 따른 할인 여부를 할인 정책에 위임 주문 결과 반환 : 주문 서비스는 할인 결과를 포함한 주문 결과 반환 주문 도메인 전체 역할과 구현을 분리해서 자유룝게 구현 객체를 조립할 수 있게 설계됐다. 덕분에 회원 저장소는 물론, 할인 정책도 유연하게 변경할 수 있다..
회원 도메인 개발 회원 엔티티 회원 등급 package hello.core.member; public enum Grade { BASIC, VIP } 회원 엔티티 package hello.core.member; public class Member { private Long id; private String name; private Grade grade; public Member(Long id, String name, Grade grade) { this.id = id; this.name = name; this.grade = grade; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String g..