Skip to content

Conversation

@discphy
Copy link
Owner

@discphy discphy commented Mar 4, 2025

📅 미션 일자

  • Day 4

✅ 미션 내용

  • validateOrder 메서드를 Order 도메인 클래스 안에서 검증함으로써 무분별한 get 메서드를 리팩토링하였습니다.
  • SOLID원칙 정리는 단순 텍스트 보다 코드를 보고 이해하는 것이 더 도움이 되어 코드 기반으로 작성하였습니다.

🔗 미션 링크

@discphy discphy self-assigned this Mar 4, 2025
Comment on lines +6 to +13
public class Items {

private final List<Item> list = new ArrayList<>();

public boolean isEmpty() {
return list.isEmpty();
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일급 컬렉션으로 의미 있는 도메인 객체로 만들어 불변성을 유지하게 끔 리팩토링하였습니다.

Comment on lines +17 to +19
public boolean hasNotInfo() {
return name.isEmpty() || email.isEmpty() || phoneNumber.isEmpty();
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단일 책임 원칙을 준수하기 위해 사용자 정보 검증하는 메서드를 Member 객체에 분리 시켜 작성하였습니다.

Comment on lines +19 to +36
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;
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조건문안에 부정 연산자를 제거하여 메서드명으로만 유추할 수 있도록 리팩토링 하였습니다.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가적으로, 도메인 레이어에서 로깅하는게 조금 신경쓰입니다.. 더 좋은 리팩토링 방안이 있을까요?

@discphy discphy marked this pull request as ready for review March 4, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants