[자동차 경주] 고민석 미션 제출합니다.#53
Conversation
eungyeong12
left a comment
There was a problem hiding this comment.
2주차 고생 많으셨습니다!
각 클래스의 역할과 코드의 흐름이 명확해서 이해하기가 수월했습니다!
| fun readCarNames(): List<String> { | ||
| println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") | ||
| val input = Console.readLine().trim() | ||
| require(input.isNotBlank()) { "자동차 이름을 입력해야 합니다." } | ||
|
|
||
| val names = input.split(",").map { it.trim() } | ||
| require(names.all { it.length in 1..5 }) { "자동차 이름은 1자 이상, 5자 이하여야 합니다." } | ||
|
|
||
| return names | ||
| } | ||
|
|
||
| fun readTryCount(): Int { | ||
| println("시도할 횟수는 몇 회인가요?") | ||
| val input = Console.readLine().trim() | ||
| val number = input.toIntOrNull() ?: throw IllegalArgumentException("시도 횟수는 숫자여야 합니다.") | ||
| require(number > 0) { "시도 횟수는 1 이상이어야 합니다." } | ||
| return number | ||
| } |
There was a problem hiding this comment.
입력과 검증을 분리하면 더 좋은 설계가 되지 않을까 싶습니다!
There was a problem hiding this comment.
피드백 감사합니다!
입력은 InputView, 검증은 별도의 Validator 객체로 분리해서 테스트하기 쉽게 구조를 개선해보겠습니다.
| fun move(number: Int) { | ||
| if (number >= 4) { | ||
| position += 1 | ||
| } | ||
| } |
There was a problem hiding this comment.
피드백 감사합니다!
4를 하드코딩한 부분은 저도 마음에 걸렸는데, 수정하면서 Cars 클래스에도 반복되는 값이 있는지 같이 점검해보겠습니다.
| fun start(): List<Car> { | ||
| repeat(tryCount) { | ||
| val randomNumbers = generateRandomNumbers() | ||
| cars.moveAll(randomNumbers) | ||
| ResultView.printRoundResult(cars.getStatus()) | ||
| } | ||
| return cars.getWinners() | ||
| } |
There was a problem hiding this comment.
도메인과 출력 로직이 결합되어 있어서 책임을 분리하면 좋을 것 같습니다!
There was a problem hiding this comment.
RacingGame이 게임 진행과 출력까지 담당하고 있어서 말씀하신 부분이 맞는 것 같습니다.
ResultView로 완전히 분리해서 도메인은 순수하게 게임 로직만 담당하도록 리팩터링하겠습니다!
joon0447
left a comment
There was a problem hiding this comment.
안녕하세요! 2주차 고생 많으셨습니다.
함수명의 통일성과 가독성이 되게 좋은 것 같네요!!
| require(name.isNotBlank()) { "자동차 이름은 비어 있을 수 없습니다." } | ||
| require(name.length <= 5) { "자동차 이름은 5자 이하여야 합니다." } |
There was a problem hiding this comment.
좋은 피드백 감사합니다!
예외 메시지도 상수화해서 일관성 있게 관리하는 방향으로 리팩터링해보겠습니다!
No description provided.