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

Step3 로또(2등) #1089

Open
wants to merge 20 commits into
base: duhanmo
Choose a base branch
from
Open

Step3 로또(2등) #1089

wants to merge 20 commits into from

Conversation

DuhanMo
Copy link

@DuhanMo DuhanMo commented Nov 27, 2024

안녕하세요 범준님! 🙂
step2 에서 남긴 피드백 반영함께 해보았어요.

그럼 리뷰 잘부탁드려요🙇‍♂️

Copy link

@ddaaac ddaaac left a comment

Choose a reason for hiding this comment

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

안녕하세요 두한님 👋

이번 단계도 너무 잘 구현해주셨네요!

몇 가지 코멘트 남겼으니 확인부탁드려요.

Comment on lines 3 to 7
@JvmInline
value class LottoNumber(val number: Int) {
init {
require(number in LOTTO_NUMBER_RANGE) { "로또 번호는 $LOTTO_MIN_NUMBER 부터 $LOTTO_MAX_NUMBER 사이어야 합니다" }
}
Copy link

Choose a reason for hiding this comment

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

요것도 값 객체로 감싸주셨군요 👍


init {
require(numbers.size == LOTTO_NUMBER_COUNT) { "로또 번호는 $LOTTO_NUMBER_COUNT 개이어야 합니다" }
this.numbers = numbers.sortedBy { it.number }.toSet()
Copy link

Choose a reason for hiding this comment

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

LottoNumber가 Comparable을 구현해도 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

네! 말씀하신대로 구현해볼게요😄

}

fun containsNumber(other: LottoNumber): Boolean {
return numbers.contains(other)
Copy link

Choose a reason for hiding this comment

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

in 키워드가 conatins에 대응하는 operator 처럼 작동하기 때문에 other in numbers 처럼 사용이 가능해요. 취향껏 사용해주시면 되겠습니다.

Copy link
Author

@DuhanMo DuhanMo Nov 27, 2024

Choose a reason for hiding this comment

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

네! 좋은 키워드 알려주셔서 감사해요😊 반영하도록 하겠습니다!👍

Comment on lines 10 to 11
SECOND(2, 5, Money(30_000_000), { matchedCount, matchBonus -> matchedCount == SECOND.matchedCount && matchBonus }),
THIRD(3, 5, Money(1_500_000), { matchedCount, matchBonus -> matchedCount == THIRD.matchedCount && !matchBonus }),
Copy link

Choose a reason for hiding this comment

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

2,3등 조건도 굉장히 꼼꼼하게 구현해주셨군요 💯
남길 코멘트가 별로 없어요... 😭

THIRD(3, 5, Money(1_500_000), { matchedCount, matchBonus -> matchedCount == THIRD.matchedCount && !matchBonus }),
FOURTH(4, 4, Money(50_000), { matchedCount, _ -> matchedCount == FOURTH.matchedCount }),
FIFTH(5, 3, Money(5_000), { matchedCount, _ -> matchedCount == FIFTH.matchedCount }),
MISS(6, 0, Money(0), { matchedCount, _ -> matchedCount in MISS.matchedCount..<FIFTH.matchedCount }),
Copy link

Choose a reason for hiding this comment

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

rangeUntil은 처음본다 했더니 1.9에 추가된 기능이군요! 하나 배워갑니다.
(a until b) 처럼 사용할 수도 있어요!

Copy link
Author

Choose a reason for hiding this comment

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

🙂a until b 처럼도 사용할 수 있군요! 좋은 정보 감사해요☺️

val rankValue: Int,
val matchedCount: Int,
val money: Money,
private val matched: (Int, Boolean) -> Boolean,
Copy link

Choose a reason for hiding this comment

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

kotiln에서 null은 "값이 없음"을 나타낼 때 유용하게 쓰일 수 있습니다.
이를 활용하여 matched를 각 enum의 값들이 갖고 있는 게 아닌 enum의 메서드 형태로 빼면 어떨까요?

val matchBonus: Boolean?
...
fun matched(Int a, Boolean b): Boolean { } 

물론 여기도 취향의 영역이긴 합니다.

Copy link
Author

Choose a reason for hiding this comment

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

네! matchBonus를 nullable하게 추출하고 말씀하신 메서드형태로 추출해볼게요 좋은 의견 감사해요 😊

Comment on lines +27 to +28
val matchedCount = winningLotto.countMatchedNumber(lotto)
val matchBonus = winningLotto.matchBonus(lotto)
Copy link

Choose a reason for hiding this comment

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

Winninglotto로 감싸둔 덕분에 깔끔하네요 👍

Copy link
Author

Choose a reason for hiding this comment

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

이전 단계에서 피드백 주신대로 해보았는데, 이번 단계 구현할 때 조금 더 깔끔해짐을 느꼈어요!
좋은 피드백 감사합니다🙇‍♂️🙂

Comment on lines +20 to +22
fun create(): LottoNumber {
return LottoNumber(LOTTO_NUMBER_RANGE.random())
}
Copy link

Choose a reason for hiding this comment

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

구현은 너무 잘 해주셔서... value class를 사용했을 떄의 장점을 공부해봐도 좋을 것 같아요. 아래는 힌트입니다!

image (show kotlin bytecode -> decompile 하면 java 코드를 볼 수 있습니다)

Copy link
Author

Choose a reason for hiding this comment

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

네! 좋은 의견감사해요😊
다시 확인해보니 해당 메서드는 테스트에서만 사용하고 있었네요🥲
해당 메서드를 제거하고 테스트하고자 했던 항목은 다른방식으로 작성해볼게요! 😀

@DuhanMo
Copy link
Author

DuhanMo commented Nov 27, 2024

안녕하세요 범준님🙂
말씀주신 피드백 반영해보았어요
RankReward를 리팩터링 하다보니 MISS 라는 값 때문에 매칭계산 로직이 애매해지더라구요 (matchedCount가 범위로써 있다보니..)
그리고 MISS순위 라는 의미와는 거리도 있어보이구요.🙄
그래서 과감하게? 제거를 해보았어요,,!

그럼 리뷰 잘부탁드려요🙇‍♂️

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