-
Notifications
You must be signed in to change notification settings - Fork 322
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
4단계 - 로또(수동) #589
base: 0923kdh
Are you sure you want to change the base?
4단계 - 로또(수동) #589
Conversation
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.
안녕하세요!
step4도 구현 잘하셨습니다! 몇 가지 코멘트를 남겼으니 확인 부탁드릴게요!
화이팅입니다 🥳🥳🥳
val resultMap = mutableMapOf<LottoTicketResult, Int>() | ||
lottoTicketBundle.lottoTickets.groupingBy { ticket -> | ||
val intersectNumbers = ticket.intersect(winningBallResult.winningBalls) | ||
val isBonusBallMatched = winningBallResult.bonusBall in ticket | ||
LottoTicketResult(intersectNumbers.size, isBonusBallMatched) | ||
}.eachCountTo(resultMap) | ||
|
||
return LottoWinningResult(resultMap.toSortedMap(getTicketResultComparator())) |
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.
val resultMap = mutableMapOf<LottoTicketResult, Int>() | |
lottoTicketBundle.lottoTickets.groupingBy { ticket -> | |
val intersectNumbers = ticket.intersect(winningBallResult.winningBalls) | |
val isBonusBallMatched = winningBallResult.bonusBall in ticket | |
LottoTicketResult(intersectNumbers.size, isBonusBallMatched) | |
}.eachCountTo(resultMap) | |
return LottoWinningResult(resultMap.toSortedMap(getTicketResultComparator())) | |
return lottoTicketBundle.lottoTickets.groupingBy { | |
val intersectNumbers = it.numbers.intersect(winningBallResult.winningBalls) | |
val isBonusBallMatched = winningBallResult.bonusBall in it.numbers | |
LottoTicketResult(intersectNumbers.size, isBonusBallMatched) | |
} | |
.eachCount() | |
.toSortedMap(getTicketResultComparator()) | |
.run { | |
LottoWinningResult(this) | |
} |
이렇게도 표현이 가능해보이네요~ 😊
그리고 LottoTicketResult를 만드는 부분에 대해서 LottoMachine에서 모두 해결하는 것보다는, LottoTicketResult에게 LottoTicketBundle과 WinningBallResult를 넘겨서 좀 더 객체 협력을 만드는 게 좋지 않을까요?
val numbers: Set<Int> = LottoNumberSelector.select(), | ||
) : Set<Int> by numbers | ||
val numbers: Set<LottoNumber>, | ||
) : Set<LottoNumber> by numbers |
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.
저번 리뷰 때 kotlin delegate 패턴에 대한 단점을 물어봤었죠~
제가 생각하는 delegate 패턴의 단점은 바로 delegate에 대한 대상의 API를 모두 사용할 수 있다라고 생각해요.
일반적인 객체는 객체 캡슐화에 대해서 내부에서는 사용하고 외부에서는 필요한 메서드만 사용할 수 있지만, delegate를 해버리는 순간 의미없는, 사용하지 않는 메서드까지 모두 외부에서 사용할 수 있기 때문에 외부에서 내부적인 부분까지 사용할 수 있어 객체간의 협력이 깨질 수도 있다고 생각해요~
val lottoTickets: List<LottoTicket> = List(lottoTicketCount.autoTicketCount) { | ||
val autoGenerateStrategy = lottoGenerateStrategyMap.getValue(TicketGenerateType.AUTO) | ||
autoGenerateStrategy.generate() | ||
} + List(lottoTicketCount.manualTicketCount) { | ||
val manualGenerateStrategy = lottoGenerateStrategyMap.getValue(TicketGenerateType.MANUAL) | ||
manualGenerateStrategy.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.
👍
@@ -1,18 +1,17 @@ | |||
package lotto.domain | |||
|
|||
import lotto.TicketResult | |||
import lotto.common.LottoTicketPolicy | |||
|
|||
class StatisticalResultExtractor( |
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.
class LottoManualGenerateStrategy : LottoGenerateStrategy { | ||
override val ticketGenerateType = TicketGenerateType.MANUAL | ||
override fun generate(): LottoTicket { | ||
val manualLottoNumberStr = readln() |
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.
view에 대한 영역이 아닐까요?
val lottoWinning = LottoMachine.process( | ||
LottoTicketBundle(lottoTicketCount, listOf(LottoAutoGenerateStrategy(), LottoManualGenerateStrategy())), | ||
WinningBallResult( | ||
WinningBalls( | ||
setOf( | ||
LottoNumber(1), LottoNumber(2), LottoNumber(3), | ||
LottoNumber(4), LottoNumber(5), LottoNumber(6) | ||
) | ||
), | ||
LottoNumber(7) | ||
) | ||
) |
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.
상세한 테스트 좋습니다! 단, 아래 테스트와 플로우가 겹쳐 보이지 않나요~?
겹쳐 보이는 부분에 대해서는 메서드화할 수 있지 않을까 하네요.
안녕하세요 리뷰어님
이번에도 꼼꼼한 리뷰 부탁드려요 :)