-
Notifications
You must be signed in to change notification settings - Fork 1.1k
๐ 4๋จ๊ณ - ๋ก๋(์๋) #4218
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
base: eundms
Are you sure you want to change the base?
Conversation
1. ๊ธฐ์กด ๋ฐฉ์: LottoGame ์ค๊ฐ ๊ฐ์ฒด ์ฌ์ฉ LottoGame game = new LottoGame(winning); GameResult gameResult = game.check(purchase); 2. ์ ์๋ ๋ฐฉ์ (ํ์ฌ ๊ตฌํ) LottoTickets tickets = LottoMachine.generateTickets(purchase); GameResult gameResult = tickets.match(winning); LottoGame ๋ฐฉ์์ ๋ฌธ์ ์ : - LottoGame.check(purchase) ๋ด๋ถ์์ ํฐ์ผ ์์ฑ์ด ์ผ์ด๋๋ฉด, ๋๋ค ์์ฑ ๋ก์ง์ด ํฌํจ๋์ด ํ ์คํธ๊ฐ ์ด๋ ค์ - ์ค๊ฐ ๊ณ์ธต์ด ๋ง์ ๋จ์ ํ ์คํธ ์์ฑ ์ ๋ชจํน์ด ํ์ํด์ง
javajigi
left a comment
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.
3๋จ๊ณ๊น์ง ๊ฐ์ฒด ์ค๊ณ๋ฅผ ์ํด์์ธ์ง ๊ทธ๋ฆฌ ํฐ ๋ณํ๋ฅผ ํ์ง ์์ ์ํ์์ 4๋จ๊ณ ๋ฏธ์
์งํํ๋ค์. ๐
Money์ Purchase ๊ฐ์ฒด ๊ด๋ จํด ํผ๋๋ฐฑ ๋จ๊ฒจ ๋ดค์ผ๋ ํ๋ฒ ๊ณ ๋ฏผํด ๋ดค์ผ๋ฉด ์ข๊ฒ ์ต๋๋ค.
| @@ -1,25 +1,34 @@ | |||
| package lotto.domain.lotto; | |||
|
|
|||
| public class Purchase { | |||
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.
Money์ Purchase์ ์ฑ
์๊ณผ ์ญํ ์ด ๋ช
ํํ์ง ์๊ณ ๋์ ์ญํ ์ด ์ ๋งคํ ์ธก๋ฉด์ด ์๋ค.
์ด ๋ ๊ฐ์ ๊ฐ์ฒด์ ์ญํ ๊ณผ ์ฑ
์์ Money์ ๊ฐ์ ๊ฐ์ฒด ํ๋๋ก ํตํฉํ ์๋ ์์๊น?
์ด ๋ ๊ฐ์ฒด์ ์ญํ ๊ณผ ์ฑ
์์ ๋ํด ์ ์ํด๋ณด๊ณ AI ํผ๋๋ฐฑ์ ๋ฐ์ ํ๋๋ก ํตํฉํ๋ ๊ฒ๊ณผ ํ์ฌ์ ๊ฐ์ ๊ตฌ์กฐ๋ก ๊ตฌํํ๋ ๊ฒ์ ๋ํด ํผ๋๋ฐฑ์ ๋ฐ์ ์ค๊ณ๋ฅผ ๊ฐ์ ํ ๋ถ๋ถ์ ์ฐพ์๋ณธ๋ค.
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.
Money ์ Purchase์ ์ฑ ์๊ณผ ์ญํ
ํ์ฌ์ ๊ฐ์ ๊ตฌ์กฐ๋ฅผ ์ ์ง
-
์ฑ ์๊ณผ ์ญํ ์ด ๋ชจํธํ ๋ถ๋ถ์ด ์๋ค
-
์๋์ ๊ฐ์ด ์ญํ ๊ณผ ์ฑ ์์ ์ ์ํ๋ค๋ฉด?
- Money: "์ผ๋ง์ธ๊ฐ?" (๊ธ์ก, VO ์ญํ )
- Purchase: "๋ฌด์์ ์ผ๋ง๋ ์๋๊ฐ?" (๊ตฌ๋งค ํ์, ๋๋ฉ์ธ ๊ฐ์ฒด)
Purchase
public class Purchase {
private final Money budget;
private final Money ticketPrice;
private final int manualCount;
private final int autoCount;
}๊ตฌ๋งค ๊ด๋ จ ๋น์ฆ๋์ค ๋ก์ง ํ์ฅ์ด ์๋ ๊ฒฝ์ฐ Purchase ๊ฐ์ฒด ๋ด์์ ์ฒ๋ฆฌ๋ ์ ์๋ค.
์๋ฅผ ๋ค์ด,
- ์๋ (๊ฑฐ์ค๋ฆ๋) ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋๋ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด ์ถ๊ฐํ ์ ์๋ค.
public Money getChange() {
return budget.subtract(getSpentAmount());
}- ํฐ์ผ์ ์ผ๋ง ์ฃผ๊ณ ์๋์ง ๋ณต์ฌํด์ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ํฐ์ผ ๊ฐ๊ฒฉ์ด ๋ณ๋๋๋ ๊ฒฝ์ฐ์ ์ํฅ์ด ์์ต๋๋ค.
๊ทธ๋ ๋ค๋ฉด, Money์ ์ถ๊ฐ๋ ์ ์๋ ๋น์ฆ๋์ค ๋ก์ง
AI์๊ฒ ๋ฌผ์ด๋ดค์ต๋๋ค
๋ก๋ ๋๋ฉ์ธ์์
// 1000์ ๋จ์ ๊ฒ์ฆ (๋ก๋๋ 1000์ ๋จ์)
public void validateUnit(int unit) {
if (this.amount.remainder(BigDecimal.valueOf(unit)) != BigDecimal.ZERO) {
throw new IllegalArgumentException("1000์ ๋จ์๋ก ์
๋ ฅํ์ธ์");
}
}์ผ๋ฐ ์ปค๋จธ์ค ๋๋ฉ์ธ์์
ํ ์ธ ์ ์ฉ,์ธ๊ธ ๊ณ์ฐ, ํตํ ๋ณํ, ๊ฒฐ์ ๊ฐ๋ฅ ์ฌ๋ถ
์ด๋ ค์ ๋ ์
Money ๊ฐ์ฒด์์
- BigDecimal wrapper ๋๋
public Money add(Money m) { return new Money(amount.add(m.amount)); }
public Money multiply(int n) { return new Money(amount.multiply(...)); }
- Money๋ง์ ๋๋ฉ์ธ ๋ก์ง ์์ด BigDecimal ์ฐ์ฐ์ ๊ฐ์ธ๊ธฐ๋ง ํจ
- ๋ฐํ ํ์ ์ผ๊ด์ฑ
add(Money) โ Money // โ
์ผ๊ด
multiply(int) โ Money // โ
์ผ๊ด
calculateRatio(Money) โ BigDecimal // โ Money ์๋
countUnits(Money) โ int // โ Money ์๋
- "๊ธ์ก / ๊ธ์ก"์ ๊ฒฐ๊ณผ๋ ๊ธ์ก์ด ์๋๋ผ ๋น์จ/๊ฐ์
- ๋๋ฉ์ธ ๋ก์ง์ ์์น
// Money์ ์์ด์ผ ํ๋?
budget.canAfford(ticketPrice)
// Purchase์ ์์ด์ผ ํ๋?
if (budget.isLessThan(ticketPrice)) { ... }
- canAfford๋ "๊ตฌ๋งค ๊ฐ๋ฅ ์ฌ๋ถ"๋ผ๋ ๋๋ฉ์ธ ํ๋จ โ Purchase ์ฑ ์
- isLessThan์ "๊ธ์ก ๋น๊ต"๋ผ๋ ๋ฒ์ฉ ์ฐ์ฐ โ Money ์ฑ ์
- ๊ฒฐ๋ก
| Money | Purchase |
|---|---|
| ๊ธ์ก ํํ (VO) | ๊ตฌ๋งค ํ์ (๋๋ฉ์ธ ๊ฐ์ฒด) |
| ๋ฒ์ฉ ์ฐ์ฐ/๋น๊ต | ๋๋ฉ์ธ ํ๋จ/๊ฒ์ฆ |
| isLessThan, countUnits | "์์ฐ์ด ์ถฉ๋ถํ๊ฐ?" |
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.
AI์ ๋ค์์ ๋ํด์๋ ๋
ผ์ํด ๋ณด๋ฉด ์ข๊ฒ ๋ค์.
Money๋ ๋จ์ํ ๊ฐ์ ๊ฐ์ง๊ณ , Purchase๊ฐ Money ๊ฐ์ ๋ํ ํ์๋ฅผ ๋ค๋ฃฌ๋ค๋ฉด Money ๊ฐ ๊ฐ์ฒด๋ฅผ ๋๋ฌด ์๋์ ์ธ ์กด์ฌ๋ก ๋ฐ๋ผ๋ณด๋ ๋๋์ด ๋๋๋ฐ์.
Money ๊ฐ ๊ฐ์ฒด๋ฅผ ์ข ๋ ๋ฅ๋์ ์ธ ๊ฐ์ฒด๋ก ๋ฐ๋ผ๋ณธ๋ค๋ฉด Purchase์ ํ์๋ฅผ ๋ด๋นํ๋ ๋ถ๋ถ๊น์ง Money๊ฐ ๋ด๋นํ๋๋ก ๊ตฌํํ๋ ๊ฒ์ ์ด๋จ๊น์ ๋ํด์ AI ๋ํ๋ฅผ ํตํด ํผ๋๋ฐฑ์ ๋ฐ์๋ณผ ๊ฒ์ ์ถ์ฒํด ๋ด
๋๋ค.
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.
2๊ฐ์ง ์ด์ ๋๋ฌธ์ ์๋ฌด๋๋ ์ด์ Money ๊ฐ์ฒด์์์ ์์ต๋ฅ ๋ฉ์๋๊ฐ ์ด์ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
- Money๋ "๊ธ์ก"์ผ ๋ฟ์ธ๋ฐ, "๋ก๋ ์์ต๋ฅ "์ด๋ผ๋ ๋๋ฉ์ธ ๊ฐ๋ ์ ์์์ผ ํจ
- Purchase๊ฐ Money์๊ฒ ๋ฌผ์ด๋ณด๊ณ ํ๋จํ๋ ์๋์ ๊ตฌ์กฐ
๋ฐ๋ผ์, ์๋์ ๊ฐ์ด Purchase ํ๋๋ง ๋จ๊ธฐ๋๋ก ํ์์ต๋๋ค.
Purchase: "๋๋ ๋ก๋ ๊ตฌ๋งค์ผ. ์ผ๋ง ์ผ๊ณ (์ง์ถ), ๋ช ์ฅ ์๋์ง(์๋) ์์. ๋น์ฒจ๊ธ์ ์๋ ค์ฃผ๋ฉด ์์ต๋ฅ ๋ ๊ณ์ฐํด์ค๊ฒ"
| int totalPrize = ranks.entrySet().stream() | ||
| public Money getTotalPrize() { | ||
| int total = ranks.entrySet().stream() | ||
| .mapToInt(entry -> entry.getKey().getPrize() * entry.getValue()) |
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.
entry์์ ๊ฐ์ ๊บผ๋ด๊ณ ์๋ค.
entry์ ๋ฉ์์ง๋ฅผ ๋ณด๋ด ๋ก์ง์ ๊ตฌํํ๋ ๊ฒ์ ์ด๋จ๊น?
javajigi
left a comment
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.
Money์ Purchase์ ๋ํ ์๊ฒฌ ์ ๋ค์์ต๋๋ค. ๐
์ด์ ๋ํ ์ ์๊ฐ๊ณผ ์ถ๊ฐ๋ก ํ์ตํด ๋ดค์ผ๋ฉด ํ๋ ๋ด์ฉ์ ๋ํด ํผ๋๋ฐฑ ๋จ๊ฒจ๋ดค์ด์.
๊ฐ์ฒด์ ์ญํ ์ ๋ํด ๊ณ ๋ฏผํด ๋ณด๋ ์๊ฐ์ ๊ฐ์ ธ๋ดค์ผ๋ฉด ์ข๊ฒ ์ต๋๋ค.
- https://vimeo.com/1137582691 ์์์ ํตํด ๊ฐ์ฒด์ ์ญํ ๊ณผ ์ด๋ฆ ์ง๊ธฐ์ ๋ํด ์ถ๊ฐ ํ์ต
- ํผ๋๋ฐฑ ๋จ๊ธด ๋ฐ์ ๊ฐ์ด AI๋ฅผ ํตํด ํผ๋๋ฐฑ ๋ฐ์๋ณด๊ธฐ
- ๋๋ผ๋ ๋ฐ๊ฐ ์๋ค๋ฉด ๋ฆฌํฉํฐ๋งํด๋ณด๊ธฐ
์์ ๊ฐ์ ์์๋ก ์ถ๊ฐ ํ์ตํด๋ณผ ๊ฒ์ ์ถ์ฒํด์.
์ด ํ์ต์ด ๊ธ๋ฐฉ ๋๋ ๊ฒ์ ์๋์์์?
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ด ํ์ต์ ํ๋ฉด์ ์๊ฐ์ ์ฒญ ๋ฏธ์
1๋จ๊ณ - ๋ ๊ฑฐ์ ์ฝ๋ ๋ฆฌํฉํฐ๋ง ๋ฏธ์
์ ์งํํ๋ฉด์ ๋ฌด์์ธ๊ฐ ๋ณธ์ธ๋ง์ ๊ฐ์ฒด์ ๋ํ ์ฒ ํ์ ์ ๋ฆฌํด ๋ณผ ๊ฒ์ ์ถ์ฒํฉ๋๋ค.
- Money ํด๋์ค ์ญ์ , Purchase๊ฐ ๊ธ์ก ๊ด๋ จ ๋ก์ง ์ง์ ๋ด๋น - Purchase: int ํ์ ์ผ๋ก ๋จ์ํ (ticketPrice, manualCount, autoCount) - ์์ต๋ฅ ๊ณ์ฐ(calculateProfitRate)์ Purchase๊ฐ ๋ด๋น - LottoMachine, GameResult, ResultView์์ Money ์์กด์ฑ ์ ๊ฑฐ
javajigi
left a comment
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.
๋ฐ๋ก mergeํ๋ ค๋ค ํน์๋ผ๋ ์ถ๊ฐ ์ฐ์ตํด๋ณด๊ณ ์ถ์ ๋ถ๋ถ์ด ์์ ์ ์์ด request changes๋ก ๋จ๊ฒจ๋ด
๋๋ค.
ํน์๋ผ๋ ์ถ๊ฐ ๋ฆฌํฉํฐ๋งํด๋ณด๊ณ ์ถ์ ๋ถ๋ถ ์์ผ๋ฉด ๋์ ํด ๋ณด์๊ณ ์.
์์ผ๋ฉด ๋ฐ๋ก ๋ฆฌ๋ทฐ ์์ฒญํด๋ ๋ฉ๋๋ค.
์๋๋ฉด ๋ก๋ ๋ฏธ์ ์ ์งํ ์ํ๋ก ๋๊ณ "์๊ฐ์ ์ฒญ - ๋ ๊ฑฐ์ ์ฝ๋ ๋ฆฌํฉํฐ๋ง" ๋ฏธ์ ์งํํ๋ค ์ผ์ ์๊ฐ์ด ์ง๋ ํ ๋ค์ ๋ฆฌํฉํฐ๋ง ๋์ ํด ๋ณด๋ ๊ฒ๋ ์ข์ ์ฐ์ต ๋ฐฉ๋ฒ์ผ ์ ์์ต๋๋ค. AI์ ํจ๊ป ๋ก๋ ๋ฏธ์ ์ ๊ฐ์ฒด ์ค๊ณ์ ๋ํ ํผ๋๋ฐฑ์ ๋ฐ์๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ผ ๊ฒ ๊ฐ์์.
LottoGame์ ์ญ์ ํ๊ณ ์ฑ ์์ ๋ค์ ๋๋๊ณ ์ ํ๋ ๊ณผ์ ์ด ์ด๋ ค์ ์ต๋๋ค