Conversation
vsh123
left a comment
There was a problem hiding this comment.
안녕하세요!
step5 빠르게 잘 구현해주셨네요 💯
몇가지 코멘트를 남겼으니 확인부탁드립니다~!
| package racingcar.view | ||
|
|
||
| object InputView { | ||
| fun carNames(): String { |
There was a problem hiding this comment.
enterCarNames 나 setCarNames 등 할 수 있긴한데, Class 자체가 Input을 하는애들이기 때문에 InputView.carNames() 에 의미가 어느정도 있다고 생각을 하는데. 어떻게 생각하시나요?!
|
|
||
| fun roundCount(): Int { | ||
| println("시도할 횟수는 몇 회인가요?") | ||
| return readln().toInt() |
There was a problem hiding this comment.
toInt()는 숫자가 들어오지 않으면 에러를 내뱉는데요!! toIntOrNull을 활용해서 숫자가 아닌 값을입력했을때의 에러처리를 고민해보면 어떨까요?
There was a problem hiding this comment.
저기서 숫자가 아니면 number format expetion이 터지겠군요. 클라이언트한테 친절한 메시지를 주는게 좋겠네요!
| } | ||
|
|
||
| companion object { | ||
| fun usernames(usernames: String): Cars { |
There was a problem hiding this comment.
정적 팩토리 메서드 네이밍 컨벤션을 읽어보고, 네이밍에 대해 고민해보면 어떨까요?
| val positions: MutableList<Position> = ArrayList() | ||
| for (car in cars) { | ||
| positions.add(car.position()) | ||
| positions.add(car.position) | ||
| } | ||
| return positions |
There was a problem hiding this comment.
kotlin collection에서 지원하는 map을 이용해서 코드를 조금 더 간결하게 짤 수 있을 것 같아요!! 고민한번 해보면 좋을 것 같습니다 :)
|
|
||
| val cars = Cars.usernames(usernames) | ||
| repeat(round) { | ||
| cars.race(RandomNumberGenerator()) |
There was a problem hiding this comment.
RandomNumberGenerator는 싱글톤 객체로 만들 수 있지 않을까요?
There was a problem hiding this comment.
싱글톤 객체가 필요한 이유가 있을까요?!
메모리적인 이득이나, 다양한 이점이 있을 것 같긴하네요.
| import racingcar.domain.Cars | ||
| import racingcar.domain.Winners | ||
|
|
||
| object OutputView { |
There was a problem hiding this comment.
outView에 Car객체를 리턴하게 되면 View레벨에서 Car 객체 안에있는 함수를 실행할 수 있을 것 같아요 :)
DTO를 활용해보면 어떨까요?
| fun gameWinner(cars: Cars) { | ||
| val winners = Winners(cars) | ||
| val winnersName = winners.getWinnerNames().joinToString(",") | ||
| println(winnersName + "가 최종 우승했습니다.") |
| } | ||
|
|
||
| fun gameWinner(cars: Cars) { | ||
| val winners = Winners(cars) |
There was a problem hiding this comment.
Winner를 구하는게 View의 역할일까요? Cars에 있어도 좋을 것 같아요 :)
| package racingcar.domain | ||
|
|
||
| class Car(private var position: Position, private val username: String) { | ||
| class Car(var position: Position, val username: String) { |
There was a problem hiding this comment.
position의 setter도 public으로 열리게된 것 같아요!
위 글을 읽어보고 프로퍼티의 setter는 private으로 막아보면 어떨까요?
아래에 대해서 리팩터링을 진행해봤습니다.
Input, Output 도 분리하였습니다.
이번 미션 하면서, 생성자나, static, 타입추론, 필드 노출 등 많은 이해가 된 것 같습니다.
미션 도움 주셔서 감사합니다 :)