Skip to content
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

[유안] 로또 미션 제출합니다. #128

Merged
merged 24 commits into from
Feb 25, 2020

Conversation

KimSeongGyu1
Copy link

No description provided.

KimSeongGyu1 added 22 commits February 18, 2020 15:26
예외조건 처리 구현
6개 숫자가 적절히 들어오지 않을 때 예외처리 구현
* 지난 커밋 때 add하지 않은 Ticket 클래스 추가 *
6개의 숫자를 체크하는 추상 클래스 구현 후 Ticket과 WinningNumbers에서 상속
Ticket 객체와 WinningNumbers 객체의 생성자에 적용
Dto 반환하는 팩토리 interface 기반 구현
무한 인풋 받기 제거
로또 번호 enum대신 싱글톤 패턴 사용
포장 안된 객체들 포장
출력형태 책임 view로 이동
잊고 add 안한 파일들 add
Copy link

@jeonghoon1107 jeonghoon1107 left a comment

Choose a reason for hiding this comment

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

안녕하세요 유안!
몇가지 피드백을 남겼으니 확인부탁드려요 :)

return NumberCache.cache.stream()
.filter(a -> a.getValue() == number)
.findAny()
.orElse(NumberCache.dummyNumber);

Choose a reason for hiding this comment

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

-1이 나와도 되는 것인가요?

Copy link
Author

Choose a reason for hiding this comment

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

당첨번호객체(WinnningNumbers)에서 6개의 숫자와 보너스 번호는 겹치면 안되는데,
DTO에서도 데이터 검증의 책임이 어느정도 있을 수 있다는 생각에 당첨번호 객체에서 가져야 할 검증 책임을 DTO로 떠넘기면서 발생한 문제인 것 같습니다.

6개의 번호 정보만 넘길 DTO를 만들 때도 DTO는 당첨번호객체의 책임을 가지고 있어서
6개의 번호와 보너스번호는 겹치면 안되었는데,
절대 기존의 번호와 겹치지 않을 번호를 생각하느라 더미 번호를 -1로 지정해주었습니다.

다시 생각해보니 무리하게 당첨번호객체의 검증 책임을 DTO로 넘기는 것이 맞지 않다고 생각되어
더미 번호를 제거하고 검증책임을 다시 돌려놓았습니다.

return InputView.enterMoney();
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
throw new IllegalArgumentException();

Choose a reason for hiding this comment

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

추적하기 쉽게 예외를 처리할때는 항상 메시지를 같이 넘겨주세요!

Copy link
Author

Choose a reason for hiding this comment

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

메시지가 없는 새로운 에러를 던지는 대신
자기 자신을 다시 던져서 메시지가 유지되도록 해봤습니다.

.findFirst()
.orElse(NO_WIN);

if (lottoRank == SECOND && !hasBonus) {

Choose a reason for hiding this comment

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

보너스 여부도 하나의 속성으로 포함하면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

보너스 여부를 속성으로 가지지 않아도 동작에 문제가 없어서 빼보았습니다.

보너스 여부를 속성으로 가진다면

  1. 코드를 읽을 때 좀 더 명시성이 높아지는 점,
  2. 혹시 다른 당첨정보에도 보너스관련 정보가 추가된다면 처리에 도움이 될 수도 있는 점
    의 장점이 있을 것으로 생각되는데
    특히 명시성이 중요할 것 같아 넣는 것이 맞다고 생각해 다시 추가했습니다.

혹시 제가 잘못 이해했다면 다시 코멘트 부탁드립니다.

return lottoTickets;
}

public static List<LottoTicket> generateTickets(int number, List<Set<Integer>> myNumbers) {

Choose a reason for hiding this comment

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

다음 단계를 미리 진행하신 것 같네요 👍
이번 단계에서는 해당 부분에 신경쓰지 않고 객체의 역할을 중점으로 하시면 좋을 것 같아요.
다음 단계에서는 해당 부분을 인터페이스로 추출하면 불필요한 클래스나 부분들이 줄어들 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

말씀하신대로 다음단계를 고려하고 만들었습니다.
다음단계에서 인터페이스를 바탕으로 확장할 수 있도록 수정하고, 불필요한 부분은 삭제했습니다.

public int findNumberOfMatchingNumbers(LottoNumbers comparingNumber) {
return this.lottoNumbers.stream()
.filter(comparingNumber::contains)
.mapToInt(number -> 1)

Choose a reason for hiding this comment

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

count를 활용해보는 것은 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

long을 반환하는 것이 마음에 들지 않아 이렇게 했는데
다시보니 count로 센 다음 int로 변환 하는 것이 더 좋아보여 수정했습니다.

public class LottoApplication {

public static void main(String[] args) {
User user = new User();

Choose a reason for hiding this comment

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

전체적인 흐름이 User라는 객체를 기반으로 흘러가는데 User 객체가 반드시 필요한가요?

Copy link
Author

Choose a reason for hiding this comment

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

현실에 기반해서 생각하다 보니 User객체를 만들었습니다.

반드시 필요한 객체도 아니고 객체지향적 사고를 연습하는데 방해가 될 수도 있을 것 같아
삭제했습니다.

로또 번호에 더미 값 삭제
에러 메시지 추적 가능하도록 변경
로또 등수 enum에 보너스 여부 추가
로또상점객체 불필요한 메서드 삭제 및 interface기반 확장성 추가
유저 객체 삭제
@KimSeongGyu1
Copy link
Author

리뷰 내용 반영하여 코드 수정했습니다.
다시 검토 부탁드립니다.

이전 수정 과정에서 잊고 적절히 수정하지 못한 점 수정
Copy link

@jeonghoon1107 jeonghoon1107 left a comment

Choose a reason for hiding this comment

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

안녕하세요 유안!
간단한 피드백 남겼으니 다음 단계 진행하면서 수정해주세요 :)


public static void main(String[] args) {
Money money = enterMoney();
List<LottoTicket> randomTickets = new RandomLottoStore().generateTickets(money);

Choose a reason for hiding this comment

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

RandomLottoStore는 인스턴스를 생성해야하는 것인가요?

Copy link
Author

Choose a reason for hiding this comment

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

Store은 static method만을 가지고,
Strategy interface를 인자로 받는 것이 더 좋을 것 같습니다.

private static Money enterMoney() {
try {
return InputView.enterMoney();
} catch (IllegalArgumentException e) {

Choose a reason for hiding this comment

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

모든 코드에 print를 하고 다시 해당 예외를 throw하고 있는데
예외를 잡았으면 특정한 행위를 하면 좋을 것 같아요.
아니면 적절한 메시지를 담아 예외를 던지면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

해당부분은 재귀를 통해 동작 제어를 하던 흔적인데
아에 삭제하는 것이 더 좋아보입니다.


private final LottoNumbers lottoNumbers;

public LottoTicket(LottoNumbersDto lottoNumbersDto) {

Choose a reason for hiding this comment

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

dto의 역할은 무엇인가요?
하나의 dto를 다른 두 개의 객체에서 사용하고 해당 dto는 두 객체가 각자 필요한 것들이 다 모여있는 것 같은데 dto가 꼭 필요한가요?

Copy link
Author

Choose a reason for hiding this comment

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

dto는 도메인과 view의 정보 전달을 당담하고 있습니다.
꼭 필요하지는 않지만 테스트하기 편한 구조가 되는 점, 도메인으로 넘어오는 데이터의 유효성이 어느정도 보장 되는 점 등에서 장점이 있다고 생각합니다.
두 객체에 공통되는 부분이 있어 하나의 dto를 같이 사용하도록 했는데, 각 객체별로 dto를 따로 가지고 있는 것이 잘못된 혼용을 막을 수 있을 것 같습니다.

@jeonghoon1107 jeonghoon1107 merged commit 21f73bc into woowacourse:kimseonggyu1 Feb 25, 2020
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