-
Notifications
You must be signed in to change notification settings - Fork 0
[미션 Day 4] 리팩토링 & SOLID 원칙 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: misson/day2
Are you sure you want to change the base?
Conversation
| public class Items { | ||
|
|
||
| private final List<Item> list = new ArrayList<>(); | ||
|
|
||
| public boolean isEmpty() { | ||
| return list.isEmpty(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일급 컬렉션으로 의미 있는 도메인 객체로 만들어 불변성을 유지하게 끔 리팩토링하였습니다.
| public boolean hasNotInfo() { | ||
| return name.isEmpty() || email.isEmpty() || phoneNumber.isEmpty(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단일 책임 원칙을 준수하기 위해 사용자 정보 검증하는 메서드를 Member 객체에 분리 시켜 작성하였습니다.
| public boolean validate() { | ||
| if (items.isEmpty()) { | ||
| log.info("주문 항목이 없습니다."); | ||
| return false; | ||
| } | ||
|
|
||
| if (totalPrice <= 0) { | ||
| log.info("올바르지 않은 총 가격입니다."); | ||
| return false; | ||
| } | ||
|
|
||
| if (member.hasNotInfo()) { | ||
| log.info("사용자 정보가 없습니다."); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조건문안에 부정 연산자를 제거하여 메서드명으로만 유추할 수 있도록 리팩토링 하였습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가적으로, 도메인 레이어에서 로깅하는게 조금 신경쓰입니다.. 더 좋은 리팩토링 방안이 있을까요?
📅 미션 일자
✅ 미션 내용
🔗 미션 링크