코드 그라데이션
회원 도메인 - 구현과 테스트 본문
회원 엔티티
Grade
public enum Grade { // 고객 등급
BASIC, VIP
}
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 getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
}
MemberRepository
public interface MemberRepository {
void save(Member member);
Member findById(Long memberId);
}
MemoryMemberRepository(구현체)
public class MemoryMemberRepository implements MemberRepository {
private static Map<Long, Member> store = new HashMap<>();
@Override
public void save(Member member) {
store.put(member.getId(), member);
}
@Override
public Member findById(Long memberId) {
return store.get(memberId);
}
}
MemberService
public interface MemberService {
void join(Member member); // 회원가입
Member findMember(Long memberId); // 회원조회
}
MemberServiceImpl(구현체)
public class MemberServiceImpl implements MemberService {
private final MemberRepository memberRepository = new MemoryMemberRepository();
@Override
public void join(Member member) {
memberRepository.save(member);
}
@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId);
}
}
728x90
'Spring > 핵심 원리 구현' 카테고리의 다른 글
주문과 할인 도메인 - 구현과 테스트 (1) | 2024.01.14 |
---|---|
주문과 할인 도메인 - 설계 (0) | 2024.01.13 |
회원 도메인 - 설계 (0) | 2024.01.12 |
프로젝트 생성, 비즈니스 요구사항과 설계 (0) | 2024.01.10 |
[이론] 3. SOLID 원칙 (0) | 2024.01.09 |
Comments