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

Step4 자동차 경주 리팩토링 #948

Open
wants to merge 5 commits into
base: youngsuk-kim
Choose a base branch
from

Conversation

youngsuk-kim
Copy link

제출이 늦었습니다.. 열심히 해보겠습니다!!

Copy link

@Flamme1004K Flamme1004K left a comment

Choose a reason for hiding this comment

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

안녕하세요!

전체적으로 구현 잘해주셨네요 💯

몇가지 코멘트를 남겼으니 확인 부탁드리겠습니다!

궁금하신 점에 대해서는 DM 부탁드립니다!!

확인 후 다시 리뷰 요청 부탁드립니다!

object RacingCarGame {
fun startGame() {
val inputValue = InputView.executeInputScreen()
CarService().execute(inputValue.tryCount, inputValue.carNumber)
val raceCars = CarService(getCarMoveRandomValue()).execute(inputValue.carNames)

Choose a reason for hiding this comment

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

스크린샷 2022-12-08 오후 8 21 46

처음에 있는 난수가 정해지면, 그 난수를 이용하여 끝까지 진행이 되는군요! 어떻게 해야 자동차들이 각자 움직일 수 있을까요?

@@ -0,0 +1,40 @@
경주할 자동차 이름을 추출 하는 기능.

Choose a reason for hiding this comment

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

description.md 파일의 위치는 src가 아닌 다른 디렉터리에 있어야하지 않을까요?

Comment on lines 14 to 20
fun getMoveCount(): Int {
return moveCount
}

fun getCarName(): String {
return name
}

Choose a reason for hiding this comment

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

코틀린의 프로퍼티는 접근자를 모두 지원하고 있어요. name에 대한 접근 제어자를 public으로 변경하면 되죠.

하지만 moveCount인 경우에는 set도 같이 쓸 수가 있기 때문에 다른 처리가 필요할거에요. 이 부분에 대해서는 한번 찾아보시겠어요~?

import src.racingcar.parseComma

class CarService(
private val carMoveRandomValue: Int

Choose a reason for hiding this comment

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

CarService는 자동차에 움직임에 대해서 랜덤인지 아닌지 알 수 없다고 생각합니다. carMobeRandomValue 보다는 자동차의 움직임에 대한 carMoveValue가 좋지 않을까요? 🤔

private val carMoveRandomValue: Int
) {

fun execute(carNames: String): MutableList<Car> {

Choose a reason for hiding this comment

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

MutableList는 가변리스트에요. 가변 리스트인 경우에는 어떤 단점이 있을까요?

Comment on lines 3 to 13
class Race(
private var cars: MutableList<Car> = mutableListOf()
) {

fun create(carNames: List<String>): Race {
for (carName in carNames) {
cars.add(Car(carName))
}

return this
}

Choose a reason for hiding this comment

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

정적 팩토리 메서드를 통하여 리팩터링 해볼까요?

[링크]

private val racingCars: List<Car>
) {
fun findWinners(): List<Car> {
return racingCars.filter { car -> car.getMoveCount() >= racingCars.maxOf { it.getMoveCount() } }

Choose a reason for hiding this comment

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

Suggested change
return racingCars.filter { car -> car.getMoveCount() >= racingCars.maxOf { it.getMoveCount() } }
val max = racingCars.maxOf { it.getMoveCount() }
return racingCars.filter { car -> car.getMoveCount() >= max }

maxOf 사용 좋습니다 👍
변경 전과 변경 후의 코드의 차이는 무엇일까요?

@@ -0,0 +1,5 @@
package src.racingcar

Choose a reason for hiding this comment

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

패키지 구조가 맞지 않네요.

import org.junit.jupiter.api.Test
import src.racingcar.domain.CarService

class CarServiceTest {

Choose a reason for hiding this comment

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

우승자에 대한 테스트 케이스는 없는걸까요?

Copy link

@Flamme1004K Flamme1004K left a comment

Choose a reason for hiding this comment

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

안녕하세요!

피드백 반영 감사합니다 💯

몇가지 코멘트를 남겼으니 확인 부탁드리겠습니다!

궁금하신 점에 대해서는 DM 부탁드립니다!!

확인 후 다시 리뷰 요청 부탁드립니다!

@@ -0,0 +1,22 @@
package src.racingcar.domain

open class Car(

Choose a reason for hiding this comment

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

open class를 사용하신 이유가 있을까요?

Comment on lines +8 to +9
var moveCount: Int = moveCount
protected set

Choose a reason for hiding this comment

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

Suggested change
var moveCount: Int = moveCount
protected set
var moveCount: Int = moveCount
private set

kotlin에서 protected와 private의 차이는 무엇일까요~?

Comment on lines +11 to +15
open fun move(carMoveNumber: Int = (MOVE_START_POINT..MOVE_END_POINT).random()): Int {
if (CAR_MOVE_CONDITION_NUMBER <= carMoveNumber) moveCount++

return moveCount
}

Choose a reason for hiding this comment

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

default arguments를 사용하셨군요! 👍

Comment on lines +7 to +11
fun start(): List<Car> {
cars.forEach { it.move() }

return cars
}

Choose a reason for hiding this comment

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

도메인 클래스에 대한 테스트는 모두 해야한다고 생각해요! race에 결과에 대한 테스트는 어떻게 해야 할까요?

참고 문서 입니다!

) {
fun findWinners(): List<Car> {
val max = racingCars.maxOf { it.moveCount }
return racingCars.filter { car -> car.moveCount >= max }

Choose a reason for hiding this comment

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

Suggested change
return racingCars.filter { car -> car.moveCount >= max }
return racingCars.filter { car -> car.moveCount == max }

== 비교로도 충분하지 않을까요?

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.

3 participants