-
Notifications
You must be signed in to change notification settings - Fork 411
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
base: youngsuk-kim
Are you sure you want to change the base?
Step4 자동차 경주 리팩토링 #948
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.
안녕하세요!
전체적으로 구현 잘해주셨네요 💯
몇가지 코멘트를 남겼으니 확인 부탁드리겠습니다!
궁금하신 점에 대해서는 DM 부탁드립니다!!
확인 후 다시 리뷰 요청 부탁드립니다!
object RacingCarGame { | ||
fun startGame() { | ||
val inputValue = InputView.executeInputScreen() | ||
CarService().execute(inputValue.tryCount, inputValue.carNumber) | ||
val raceCars = CarService(getCarMoveRandomValue()).execute(inputValue.carNames) |
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.
@@ -0,0 +1,40 @@ | |||
경주할 자동차 이름을 추출 하는 기능. |
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.
description.md
파일의 위치는 src가 아닌 다른 디렉터리에 있어야하지 않을까요?
fun getMoveCount(): Int { | ||
return moveCount | ||
} | ||
|
||
fun getCarName(): String { | ||
return name | ||
} |
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.
코틀린의 프로퍼티는 접근자를 모두 지원하고 있어요. name에 대한 접근 제어자를 public으로 변경하면 되죠.
하지만 moveCount인 경우에는 set도 같이 쓸 수가 있기 때문에 다른 처리가 필요할거에요. 이 부분에 대해서는 한번 찾아보시겠어요~?
import src.racingcar.parseComma | ||
|
||
class CarService( | ||
private val carMoveRandomValue: Int |
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.
CarService는 자동차에 움직임에 대해서 랜덤인지 아닌지 알 수 없다고 생각합니다. carMobeRandomValue 보다는 자동차의 움직임에 대한 carMoveValue가 좋지 않을까요? 🤔
private val carMoveRandomValue: Int | ||
) { | ||
|
||
fun execute(carNames: String): MutableList<Car> { |
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.
MutableList는 가변리스트에요. 가변 리스트인 경우에는 어떤 단점이 있을까요?
class Race( | ||
private var cars: MutableList<Car> = mutableListOf() | ||
) { | ||
|
||
fun create(carNames: List<String>): Race { | ||
for (carName in carNames) { | ||
cars.add(Car(carName)) | ||
} | ||
|
||
return this | ||
} |
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.
private val racingCars: List<Car> | ||
) { | ||
fun findWinners(): List<Car> { | ||
return racingCars.filter { car -> car.getMoveCount() >= racingCars.maxOf { it.getMoveCount() } } |
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.
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 |
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.
패키지 구조가 맞지 않네요.
import org.junit.jupiter.api.Test | ||
import src.racingcar.domain.CarService | ||
|
||
class CarServiceTest { |
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.
우승자에 대한 테스트 케이스는 없는걸까요?
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.
안녕하세요!
피드백 반영 감사합니다 💯
몇가지 코멘트를 남겼으니 확인 부탁드리겠습니다!
궁금하신 점에 대해서는 DM 부탁드립니다!!
확인 후 다시 리뷰 요청 부탁드립니다!
@@ -0,0 +1,22 @@ | |||
package src.racingcar.domain | |||
|
|||
open class Car( |
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.
open class를 사용하신 이유가 있을까요?
var moveCount: Int = moveCount | ||
protected set |
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.
var moveCount: Int = moveCount | |
protected set | |
var moveCount: Int = moveCount | |
private set |
kotlin에서 protected와 private의 차이는 무엇일까요~?
open fun move(carMoveNumber: Int = (MOVE_START_POINT..MOVE_END_POINT).random()): Int { | ||
if (CAR_MOVE_CONDITION_NUMBER <= carMoveNumber) moveCount++ | ||
|
||
return moveCount | ||
} |
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.
default arguments를 사용하셨군요! 👍
fun start(): List<Car> { | ||
cars.forEach { it.move() } | ||
|
||
return cars | ||
} |
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.
도메인 클래스에 대한 테스트는 모두 해야한다고 생각해요! race에 결과에 대한 테스트는 어떻게 해야 할까요?
참고 문서 입니다!
) { | ||
fun findWinners(): List<Car> { | ||
val max = racingCars.maxOf { it.moveCount } | ||
return racingCars.filter { car -> car.moveCount >= max } |
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.
return racingCars.filter { car -> car.moveCount >= max } | |
return racingCars.filter { car -> car.moveCount == max } |
==
비교로도 충분하지 않을까요?
제출이 늦었습니다.. 열심히 해보겠습니다!!