Conversation
| class Game { | ||
| private int currentMove = 0; | ||
| private int maxMove; | ||
| private Car[] cars; | ||
| private ArrayList<String> winners; | ||
| Game() {} | ||
| public void initiateGame(){ | ||
|
|
||
| makeCars(inputCarNames()); | ||
| maxMove = inputMaxMoves(); | ||
| playGame(); |
There was a problem hiding this comment.
하나의 파일에는 하나의 public Class만 존재하거나, Sub class만 두는것이 일반적입니다. 혹시 Application안에서 다른 sub class 형태로 Game을 구현하신 이유가 있으신가요?
There was a problem hiding this comment.
아직 java가 익숙치 않아서 그랬던 것 같습니다. 확실히 분리하는 편이 더 적절한 것 같아요!
| public String[] inputCarNames() { | ||
|
|
||
| System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); | ||
| String userInput = readLine(); |
There was a problem hiding this comment.
static import 보다는 Console 객체를 import 하는 것이 조금 더 좋아보입니다. readLine이 Game안에 있는 메소드인지 아닌지 알기 조금 어려운것 같습니다.
There was a problem hiding this comment.
알겠습니다. 난수 생성부분도 비슷하게 고치는게 괜찮을 것 같네요!
| checkValidNames(cars); | ||
| } catch(IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| return inputCarNames(); |
src/main/java/racingcar/Car.java
Outdated
| public static String repeatString(int count, String str) { | ||
| StringBuilder result = new StringBuilder(); | ||
| for(int cnt = 0; cnt < count; cnt++){ | ||
| result.append(str); | ||
| } | ||
| return result.toString(); | ||
| } |
There was a problem hiding this comment.
repeat String이 자동차가 가지고 있어야 하는 함수인지는 잘 모르겠습니다. Utility class로 분리하거나, private으로 숨겨보는건 어떠신가요?
There was a problem hiding this comment.
Car 객체에 국한되지 않고 범용적으로 사용하려고 구현했던거라 분리하는 쪽이 더 적절한 것 같네요! 작성하면서도 Car와 아무 상관없지않나?하는 생각이 들었었습니다 :)
src/main/java/racingcar/Car.java
Outdated
| public boolean canAdvance() { | ||
|
|
||
| return pickNumberInRange(0, 9) >= 4; | ||
| } |
There was a problem hiding this comment.
해당 함수도 외부에 공개될 필요가 없다면 private을 고민해 보시는것도 좋을것 같습니다.
| public boolean canAdvance() { | |
| return pickNumberInRange(0, 9) >= 4; | |
| } | |
| public boolean canAdvance() { | |
| return pickNumberInRange(0, 9) >= 4; | |
| } |
choi5798
left a comment
There was a problem hiding this comment.
아직 Java 에 익숙치 않으신 것 같은데 그래도 깔끔하게 잘 짜신 것 같습니다. LGTM!
| private int currentMove = 0; | ||
| private int maxMove; | ||
| private Car[] cars; | ||
| private ArrayList<String> winners; |
There was a problem hiding this comment.
객체들을 선언할 경우에는 보통 인터페이스로 구현되어 있는 가장 최상위 부모를 기준으로 정의해주는 것이 좋아요. SOLID 원칙 중 하나인데 이 번에 참고하시면 좋을 것 같아요
| private int maxMove; | ||
| private Car[] cars; | ||
| private ArrayList<String> winners; | ||
| Game() {} |
There was a problem hiding this comment.
보통 Java에서는 class의 생성자를 만들지 않으면 default 생성자가 기본적으로 존재하는데 따로 비어있는 생성자를 만드신 이유가 있을까요?
There was a problem hiding this comment.
변수들을 초기화하려고 만들어 두었다가 깜빡한것 같습니다. 지우는 편이 깔끔하겠네요!
| playGame(); | ||
| } | ||
|
|
||
| public void makeCars(String[] carNames) { |
There was a problem hiding this comment.
같은 class 안에서만 쓰이는 함수라면 접근 범위를 private으로 하는 걸 고민해 보시는 것도 좋을 것 같습니다
| return inputCarNames(); | ||
| } |
| } | ||
| } | ||
|
|
||
| public int inputMaxMoves() { |
There was a problem hiding this comment.
숫자를 입력받아 return까지 하는 함수라면 입력부분을 따로 빼낸 뒤 함수 이름을 input으로 시작하는 것 보다는 get으로 시작하는 것은 어떨까요?
There was a problem hiding this comment.
input부분을 분리하려고 생각했는데 메소드 이름도 적절히 바꾸면 더 좋을 것 같네요. 좋은 의견 감사합니다!
src/main/java/racingcar/Car.java
Outdated
| return this.name; | ||
| } | ||
|
|
||
| public void printCar() { |
There was a problem hiding this comment.
자동차의 어떤 성분을 출력하는지 함수 이름에 명시되어 있으면 좋을 것 같습니다!
src/main/java/racingcar/Car.java
Outdated
| position++; | ||
| } | ||
| } | ||
| public boolean canAdvance() { |
There was a problem hiding this comment.
전진 가능한지 조건만 딱 깔끔하게 반환하는게 보기 좋은 것 같습니다
src/main/java/racingcar/Car.java
Outdated
| } | ||
|
|
||
| public static String repeatString(int count, String str) { | ||
| StringBuilder result = new StringBuilder(); |
There was a problem hiding this comment.
여기서 StringBuilder 의 변수이름을 result 라고 지으신 이유가 있으실까요? 보통 메소드 내부에서 해당 타입의 객체가 하나만 있다면 객체의 이름 앞글자만 소문자로 바꾼 채 그대로 변수 이름으로 쓰는 것이 가독성이 좋아보이긴 합니다.
There was a problem hiding this comment.
큰 의미없이 이름을 지었는데 가독성을 고려하는 것도 확실히 중요한 것 같네요. 지식이 늘었습니다!
| public String getPositionString() { | ||
|
|
||
| return Utility.repeatString(position, "-"); | ||
| } |
There was a problem hiding this comment.
Utility.repeatString을 사용해서 출력하는 방법 좋은 것 같습니다!
|
|
||
| int maxPosition = 0; | ||
| for (Car car : cars) { | ||
| maxPosition = Math.max(maxPosition, car.getPosition()); |
There was a problem hiding this comment.
if문으로 maxPosition 값을 갱신하는 것이 아닌, Math.max를 사용해 maxPosition을 갱신하는 방법 좋은 것 같습니다!
There was a problem hiding this comment.
들여쓰기 규칙을 신경쓰다보니 더 간략하게 표현할 수 있는 방법으로 구현한 것 같습니다. 감사합니다 :)
스프링 스터디 1주차
코드 설명
Application.java
Application Class
Game Class
Car.java
Car Class
코드 리뷰
코드 리뷰후 개선점