package hello.demo.discount;
import hello.demo.member.Grade;
import hello.demo.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*discountPercent/100;
}else{
return 0;
}
}
}
public class OrderServiceImpl implements OrderService{
private final MemberRepository memberRepository = new MemoryMemberRepository();
//private final DiscountPolicy discountPolicy = new FixDiscountPolicy();
private final DiscountPolicy discountPolicy = new RateDiscountPolicy();
=> OCP, DIP 같은 객체지향 설계 원칙을 충실히 준수하지 못했다
그렇게 보이지만 사실은 아니다.
1) 추상(인터페이스) 의존: DiscountPolicy
2) 구체(구현) 클래스: FixDiscountPolicy , RateDiscountPolicy