-
Notifications
You must be signed in to change notification settings - Fork 330
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
[1단계 - 로또 구현] 케빈(박진홍) 미션 제출합니다. #228
Conversation
필드변수명 변경에 따라 getter 또한 변경한다
등수에 따른 개수라는 의미를 직관적으로 살리기 위해 변경한다
자동으로 티켓을 발권한다는 역할을 메서드명에 드러나도록 변경
- 각 상수들의 접두로 PRIZE를 추가한다. - 상금 상수의 가독성을 위해 언더바를 추가한다.
counts가 아닌 ticketCounts라고 명시한다.
- 각 메서드가 어떤 내용을 출력하는지를 명시해준다. - 또한 반복문을 삭제하고 람다 스트림을 이용한다.
학습 로그[JDK] Stream API - 4내용
링크[JDK] Map API - 2내용
[Design Pattern] Singleton - 3내용
링크[OOP] 표준 vs Custom Exception - 3내용
링크[OOP] 상속보단 컴포지션을 - 5내용
링크[JDK] EnumMap - 2내용
링크[TDD] 테스트 주도 개발 - 3내용
[MVC] DTO - 3내용
링크 |
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.
안녕하세요 케빈! 지노입니다!
우선 리뷰가 늦어져서 죄송해요😭
빠르게 구현 잘 해주셨어요! 👍
몇 가지 코멘트 남겼습니다!
읽어보시고 궁금하시거나 다르게 생각하는 부분이 있다면 함께 이야기 나눠보면 좋을 거 같아요 :)
언제든 편하게 dm 주세요! 감사합니다!
public static LottoNumber from(int number) { | ||
return CACHE.computeIfAbsent(number, LottoNumber::new); | ||
} |
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 interface LottoNumberGenerator { | ||
public List<Integer> generate(); | ||
} |
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 입니다!
public LottoStatistics getStatistics(WinningLottoTicket winningLottoTicket) { | ||
Map<LottoRank, Long> statistics = lottoTickets.stream() | ||
.map(winningLottoTicket::compareNumbers) | ||
.collect(Collectors.groupingBy(lottoRank -> lottoRank, () -> new EnumMap<>(LottoRank.class), | ||
Collectors.counting())); | ||
return new LottoStatistics(statistics); | ||
} |
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.
EnumMap 👍
public double calculateYield(PurchasingPrice purchasingPrice) { | ||
long prizeMoneyTotal = calculatePrizeMoneyTotal(); | ||
int denominatorCost = purchasingPrice.getPrice(); | ||
return (((double) prizeMoneyTotal) / denominatorCost); | ||
} |
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.
뷰에서 사용되는 로직이네요. 뷰에서 도메인 객체에게 메세지를 보내는 것에 대해서 고민해보면 좋을 거 같아요 :)
뷰가 웹으로 바뀐다면 어떻게 될까요?
private LottoRank(int matchCounts, boolean isBonusBall, int prizeMoney) { | ||
this.matchCounts = matchCounts; | ||
this.isBonusBall = isBonusBall; | ||
this.prizeMoney = prizeMoney; | ||
} |
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.
enum은 생성자를 디폴트로 사용합니다! private일 필요는 없어요!
private LottoRank(int matchCounts, boolean isBonusBall, int prizeMoney) { | |
this.matchCounts = matchCounts; | |
this.isBonusBall = isBonusBall; | |
this.prizeMoney = prizeMoney; | |
} | |
LottoRank(int matchCounts, boolean isBonusBall, int prizeMoney) { | |
this.matchCounts = matchCounts; | |
this.isBonusBall = isBonusBall; | |
this.prizeMoney = prizeMoney; | |
} |
public long getTicketCountsByRank(LottoRank lottoRank) { | ||
return statisticsMap.computeIfAbsent(lottoRank, key -> ZERO); | ||
} |
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.
이 메서드도 마찬가지로 뷰에서 사용하는 메서드네요!
@DisplayName("로또 번호는 싱글톤 객체이다") | ||
@Test | ||
void isSingleton() { | ||
LottoNumber lottoNumber = LottoNumber.from(1); | ||
LottoNumber target = LottoNumber.from(1); | ||
|
||
assertThat(lottoNumber).isEqualTo(target); | ||
} |
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.
LottoNumber는 value object로 만들 수도 있겠네요!
https://woowacourse.github.io/javable/post/2020-06-11-value-object/
private final List<LottoNumber> lottoNumbers; | ||
|
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.
더 쉬운 방법이 있었네요.... 😅😅
public boolean contains(LottoNumber lottoNumber) { | ||
return lottoNumbers.contains(lottoNumber); | ||
} |
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.
LottoNumber 객체에게 같은 숫자인지 물어보는 방법은 없을까요??
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 contains(LottoNumber lottoNumber) {
return lottoNumbers.stream()
.anyMatch(lottoNumberOfTicket -> lottoNumberOfTicket.hasSameNumber(lottoNumber);
}
같은 형태의 코드를 말씀하시는 것일까요? 해당 부분의 피드백이 잘 이해가 되지 않네요!
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 class LottoNumber {
..
public boolean match(LottoNumber LottoNumber) {
return this.value == value;
}
}
이런 형태로 LottoNumber에게 메세지를 보낼 수도 있을거 같아서 남긴 피드백이였습니다!
public int getMatchCounts(LottoTicket lottoTicket) { | ||
return (int) lottoNumbers.stream() | ||
.filter(lottoTicket::contains) | ||
.count(); | ||
} |
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.
get보다 더 좋은 이름은 없을까요??
- 열거형 생성자는 기본 default를 사용한다. - 인터페이스 추상 메서드의 접근 제어자의 public은 생략한다.
- getStatistics 등의 메서드 명 또한 checkResult로 직관되게 변경
- 구입가격 객체는 양의 정수만을 허용하도록 변경한다.
도메인 객체로 메시지를 보내던 기존 방식을 외부에서 주입받은 수익률을 바로 출력하도록 변경한다.
LottoTicket은 Set이기 때문에 정렬을 View단으로 넘긴다
안녕하세요. 피드백을 반영하는 과정에서 코드의 구조가 다소 많이 변경되었네요.
중복을 허용하지 않는 자료구조 피드백에 대해서 Set을 적용하도록 코드를 변경했습니다. 그리고 지적해주신 메서드 네이밍에 대해 고민해보면서, 기타 직관적이지 않은 클래스 및 메서드 네임들에 대해 전부 리팩토링해보았습니다. (예 : LottoStatistics -> LottoResult 등) 또한 뷰에서 도메인 객체에게 메시지를 보내는 것에 고민해보았는데요. 말씀하신대로 요구사항이 웹으로 바뀌면... 기껏 도메인에서 뷰에 필요한 정보들(DTO, JSON 등)을 만들어 보내줬는데 뷰가 도메인쪽으로 추가 정보를 달라고 다시 요청하는(?) 이상한 형태가 되네요. View에서 도메인 객체에게 메시지를 보내 그 때 그때 필요한 정보를 받기보다는, 도메인 객체가 제공하는 DTO 성격의 데이터를 파싱하여 View를 보여주는 방식으로 변경해보았습니다! |
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.
안녕하세요 케빈!
주말까지 step1 진행하신다고 수고 많으셨어요! 👍
step2에서 만나요! 감사합니다!
public int getPurchasingPrice() { | ||
return lottoTickets.size() * LOTTO_TICKET_PRICE; | ||
} | ||
|
||
public int getTicketCounts() { | ||
return lottoTickets.size(); | ||
} | ||
|
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.
get 보다 더 좋은 이름은 없을까요??
public List<LottoNumber> getLottoNumbers() { | ||
return Collections.unmodifiableList(new ArrayList<>(lottoNumbers)); | ||
} |
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.
getter 메서드가 내부와 다른 자료구조를 던져주네요!
public List<LottoNumber> getLottoNumbers() { | |
return Collections.unmodifiableList(new ArrayList<>(lottoNumbers)); | |
} | |
public Set<LottoNumber> getLottoNumbers() { | |
return Collections.unmodifiableSet(lottoNumbers); | |
} |
안녕하세요.
스트림, 람다 등을 연습하고자 반복문 사용을 최대한 지양했는데 다소 억지스럽거나 가독성이 떨어진다면 지적해주세요!
리뷰잘부탁드리겠습니다. :D