-
Notifications
You must be signed in to change notification settings - Fork 305
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
Step4 #1003
base: gongwho
Are you sure you want to change the base?
Step4 #1003
Changes from 4 commits
45ba384
097da6d
a5dd616
9a4122a
1b40de8
604d93d
3484985
c30e951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ package lotto | |
import lotto.domain.LottoPurchaseOrder | ||
import lotto.domain.LottoResult | ||
import lotto.domain.LottoTicket | ||
import lotto.provider.ticket.AutoTicketProvider | ||
import lotto.provider.ticket.LottoTicketsProvider | ||
import lotto.domain.LottoTickets | ||
import lotto.domain.RankResult | ||
import lotto.generator.ticket.ActualLottoShop | ||
import lotto.generator.ticket.LottoShop | ||
import lotto.view.InputView | ||
import lotto.view.ResultView | ||
import lotto.view.UserInputView | ||
|
@@ -13,16 +15,16 @@ class LottoSimulator( | |
private val inputView: InputView, | ||
private val resultView: ResultView, | ||
) { | ||
fun simulate(lottoTicketsProvider: LottoTicketsProvider): LottoResult { | ||
fun simulate(lottoShop: LottoShop): LottoResult { | ||
val purchaseOrder = LottoPurchaseOrder( | ||
budget = inputView.getBudget(), | ||
ticketPrice = LottoTicket.PRICE, | ||
) | ||
|
||
val lottoTickets = lottoTicketsProvider.provide(purchaseOrder.ticketCount) | ||
inputView.printPurchasedLotto(lottoTickets) | ||
val lottoTickets = generateLottoTickets(lottoShop, purchaseOrder.ticketCount) | ||
|
||
val winningNumber = inputView.getWinningNumber() | ||
|
||
val lottoResult = lottoTickets.getRankResult(winningNumber) | ||
|
||
val result = LottoResult( | ||
|
@@ -31,15 +33,34 @@ class LottoSimulator( | |
remainder = purchaseOrder.remainder | ||
) | ||
|
||
printLottoResult(lottoResult, result) | ||
|
||
return result | ||
} | ||
|
||
private fun printLottoResult(lottoResult: RankResult, result: LottoResult) { | ||
resultView.printRankResults(lottoResult) | ||
resultView.printResult(result) | ||
return result | ||
} | ||
|
||
private fun generateLottoTickets(lottoShop: LottoShop, ticketCount: Int): LottoTickets { | ||
val manualLottoCount = inputView.getManualLottoCount() | ||
|
||
val manualTickets = if (manualLottoCount != 0) { | ||
inputView.printManualLottoInputString() | ||
lottoShop.provideManualTickets(manualLottoCount) | ||
} else LottoTickets(listOf()) | ||
|
||
val autoTickets = lottoShop.provideAutoTickets(ticketCount - manualLottoCount) | ||
inputView.printPurchasedLotto(autoLottoTickets = autoTickets, manualLottoTickets = manualTickets) | ||
|
||
return LottoTickets(manualTickets.lottoTicketList + autoTickets.lottoTicketList) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LottoSimulator내에서 계산하기보단, |
||
} | ||
|
||
fun main() { | ||
LottoSimulator( | ||
UserInputView(), | ||
ResultView() | ||
).simulate(lottoTicketsProvider = AutoTicketProvider) | ||
).simulate(lottoShop = ActualLottoShop) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||||||||||||
package lotto.generator.ticket | ||||||||||||||||||||
|
||||||||||||||||||||
import lotto.domain.LottoTickets | ||||||||||||||||||||
|
||||||||||||||||||||
object ActualLottoShop : LottoShop { | ||||||||||||||||||||
override fun provideAutoTickets(ticketCount: Int): LottoTickets = AutoTicketGenerator.create(ticketCount) | ||||||||||||||||||||
override fun provideManualTickets(ticketCount: Int): LottoTickets = ManualTicketGenerator.create(ticketCount) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AutoTicketGenerator, ManualTicketGenerator를 싱글턴으로 접근하는구조네요!
Suggested change
위 처럼 바꾼 코드랑은 어떤점이 다를까요? 고민해보시면 좋을거같아요! |
||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package lotto.generator.ticket | ||
|
||
import lotto.domain.LottoTickets | ||
|
||
interface LottoShop { | ||
fun provideAutoTickets(ticketCount: Int): LottoTickets | ||
fun provideManualTickets(ticketCount: Int): LottoTickets | ||
} | ||
|
||
interface TicketGenerator { | ||
fun create(ticketCount: Int): LottoTickets | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package lotto.generator.ticket | ||
|
||
import lotto.domain.LottoNumber | ||
import lotto.domain.LottoTicket | ||
import lotto.domain.LottoTickets | ||
|
||
object ManualTicketGenerator : TicketGenerator { | ||
override fun create(ticketCount: Int): LottoTickets { | ||
val lottoTicketList = mutableListOf<LottoTicket>() | ||
repeat(ticketCount) { | ||
val lottoTicket = LottoTicket(readln().trim().split(",").map { it.toInt() }.map { LottoNumber(it) }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TicketGenerator는 domain 로직이라고 볼수도 있을거같아요, |
||
lottoTicketList.add(lottoTicket) | ||
} | ||
return LottoTickets(lottoTicketList) | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lotto.generator.ticket | ||
|
||
import lotto.domain.LottoTickets | ||
|
||
class ExactTicketGenerator(private val lottoTickets: LottoTickets) : TicketGenerator { | ||
override fun create(ticketCount: Int): LottoTickets = lottoTickets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lottoTickets의 사이즈와 ticketCount 가 일치하지 않는다면 테스트에 문제가 생길수도 있을거같아요 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package lotto.generator.ticket | ||
|
||
import lotto.domain.LottoTickets | ||
|
||
class MockLottoShop(private val ticketGenerateStrategy: ExactTicketGenerator) : LottoShop { | ||
override fun provideAutoTickets(ticketCount: Int): LottoTickets = ticketGenerateStrategy.create(ticketCount) | ||
override fun provideManualTickets(ticketCount: Int): LottoTickets = LottoTickets(listOf()) | ||
} |
This file was deleted.
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.
단순히 print를 실행하기보단,
함수에게 책임을주고, 행위를 위임해보면 어떨까요?
LottoSimulator가 하나씩 print에 관여하기보다, inputView에게 메세지를 전달해보아요!
inputView.getManualNumbers(manualLottoCount)
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 의 역할과 lotto shop 의 역할을 어디까지로 설정할 지 고민이 좀 되는 부분이네요 ㅎㅎ 일단 가장 적절해 보이는 방식으로 작성해 보겠습니다!