Conversation
kouz95
left a comment
There was a problem hiding this comment.
고생하셨습니다!
리뷰 확인해주시고, 혹시라도 이해가 안되는 부분이 있거나 질문이 있으시다면 코멘트 남겨주세요! 🙂
src/main/java/domain/GamePlayer.java
Outdated
| if (randomNumber >= WINNER_CONDITION) | ||
| car.moveForward(); |
src/main/java/domain/GamePlayer.java
Outdated
| ArrayList<Car> inputNames() { | ||
| String messageCode = Message.GeneralMessages.INPUT_NAMEOFCAR.getMessage(); | ||
| printer.printMessages(messageCode); | ||
| ArrayList<String> names = new ArrayList<>(Arrays.asList(receiver.receiveName())); | ||
|
|
||
| return makeCarList(names); | ||
| } | ||
|
|
||
| ArrayList<Car> makeCarList(List<String> names) { | ||
| ArrayList<Car> cars = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < names.size(); i++) | ||
| cars.add(new Car(names.get(i))); | ||
|
|
||
| return cars; | ||
| } |
There was a problem hiding this comment.
| ArrayList<Car> inputNames() { | |
| String messageCode = Message.GeneralMessages.INPUT_NAMEOFCAR.getMessage(); | |
| printer.printMessages(messageCode); | |
| ArrayList<String> names = new ArrayList<>(Arrays.asList(receiver.receiveName())); | |
| return makeCarList(names); | |
| } | |
| ArrayList<Car> makeCarList(List<String> names) { | |
| ArrayList<Car> cars = new ArrayList<>(); | |
| for (int i = 0; i < names.size(); i++) | |
| cars.add(new Car(names.get(i))); | |
| return cars; | |
| } | |
| List<Car> inputNames() { | |
| String messageCode = Message.GeneralMessages.INPUT_NAMEOFCAR.getMessage(); | |
| printer.printMessages(messageCode); | |
| List<String> names = new ArrayList<>(Arrays.asList(receiver.receiveName())); | |
| return makeCarList(names); | |
| } | |
| List<Car> makeCarList(List<String> names) { | |
| List<Car> cars = new ArrayList<>(); | |
| for (int i = 0; i < names.size(); i++) | |
| cars.add(new Car(names.get(i))); | |
| return cars; | |
| } |
자바의 유명한 규칙중엔 program to interfaces not implementations 라는 부분이 있습니다.
객체 지향 기초 이야기 3, 유연함(Flexibility)
위 글 참고해보시면 좋을것 같아요 🙂
src/main/java/domain/GamePlayer.java
Outdated
| this.generator = new Generator(); | ||
| } | ||
|
|
||
| void judgeAndMove(Car car, int randomNumber) { |
There was a problem hiding this comment.
judgeAndMove 라는것 자체로 메소드가 두가지 일을 하고 있다고 생각할 수 있지 않을까요?
메소드는 한가지 일만 할 수 있도록 메소드를 분리해봅시다 🙂
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class GamePlayer { |
There was a problem hiding this comment.
대부분의 메소드의 접근 제한자가 default인데 의도하신 건가요?
There was a problem hiding this comment.
처음에 public으로 설정했다가 동민님이 외부에서 사용하지 않는데 굳이 public을 사용한 이유가 있냐고 피드백을 주셔서 이에 대해 고민해 본 이후 default로 변경했습니다!
src/main/java/domain/Validator.java
Outdated
| private static final Character COMMA = ','; | ||
| private static final String NOTHING = ""; | ||
|
|
||
| Printer printer; |
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class ValidatorTest { |
There was a problem hiding this comment.
실패하는 테스트가 많습니다!
테스트는 전부 통과해야합니다. 예외를 테스트하는 경우엔 예외가 발생한다는것을 테스트 해주세요!
refactor: 컨벤션 수정 Co-authored-by: Gyeongjun Kim <lastpuzly@gmail.com>
refactor: 컨벤션 수정 Co-authored-by: Gyeongjun Kim <lastpuzly@gmail.com>
kouz95
left a comment
There was a problem hiding this comment.
추가적인 리뷰 드렸으니 확인해주세요 🙏
리뷰 이외에도 컨벤션이 지켜지지 않은 부분이 있는데 전체적으로 확인해보시면 좋을것 같아요.
for문이나 if, while문 사이의 공백 같은 경우는 IDE을 이용하여 전체 reformat을 할 수 있으니 시도해보세요! 정렬하고 싶은 파일이나 패키지에 우클릭하여 Reformat Code를 누르면 됩니다 🙂
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class GamePlayer { |
There was a problem hiding this comment.
아마 클래스 내부에서만 사용되는 메소드를 public으로 설정해서 그런 피드백을 주지 않았나 생각이 되네요 🙂
클래스 내부에서만 사용되는 메소드는 private, 외부에서 메세지를 전달받는 메소드는 public으로 설정하는 것이 좋을 것 같아요.
| printer = new Printer(); | ||
| } | ||
|
|
||
| public boolean validateName(String s) { |
|
|
||
| public boolean inputSameName(String s) { | ||
| String messageCode = Message.ExceptionMessages.INPUT_SAME_NAME.getMessage(); | ||
| List<String> carNames = Arrays.asList(s.split(",")); |
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"123,!@a,BDs5", ",,asd,asd,"}) | ||
| //이름 유효성 체크 |
There was a problem hiding this comment.
테스트 메소드의 의도를 드러낼땐 @DisplayName 을 사용하여 표현해줄수 있습니다.
@ParameterizedTest의 경우엔 name 속성에 DisplayName을 부여할 수 있어요 🙂
| List<Car> inputNames() { | ||
| String messageCode = Message.GeneralMessages.INPUT_NAMEOFCAR.getMessage(); | ||
| printer.printMessages(messageCode); | ||
| List<String> names = new ArrayList<>(Arrays.asList(receiver.receiveName())); |
There was a problem hiding this comment.
| List<String> names = new ArrayList<>(Arrays.asList(receiver.receiveName())); | |
| List<String> names = Arrays.asList(receiver.receiveName()); |
new ArrayList<>()를 안해줘도 괜찮습니다.
| return receiver.receiveNumber(); | ||
| } | ||
|
|
||
| List<Car> makeCarList(List<String> names) { |
There was a problem hiding this comment.
List<Car> 라는 return type으로 이미 List임을 알 수 있지 않을까요?
의미 있게 구분하라.
구분 짓지 못하는 변수명은 의미가 없다. 예를 들어 ProductInfo와 ProductData의 개념은 분리 되는가?
또 변수 뒤에 타입을 작성하는 것도 의미가 없다면 좋지 않다. NameString과 Name이 다른 점이 무엇인가?- Clean Code
makeCars 정도로 표현 할 수 있을 것 같아요 🙂
| public static String makeWinnerToString(List<Car> cars) { | ||
| StringBuilder winner = new StringBuilder(cars.get(0).getName()); | ||
|
|
||
| if (cars.size() > 1) { | ||
| for (int i = 1; i < cars.size(); i++) { | ||
| winner.append(", ").append(cars.get(i).getName()); | ||
| } | ||
| } | ||
|
|
||
| return winner.toString(); | ||
| } |
There was a problem hiding this comment.
Winner가 우승자가 컴마로 이어진다는("a,b") 사실을 알 필요가 있을까요?
Winner의 책임은 우승자가 누군지만 알려줘도 괜찮지 않을까요?
비지니스 로직과 뷰로직을 분리해봅시다!
| public String getProgressWithSymbol() { | ||
| String progress = ""; | ||
| for(int i = 0;i < this.position;i++) { | ||
| progress += "-"; | ||
| } | ||
|
|
||
| return progress; | ||
| } |
There was a problem hiding this comment.
현재 위치를 "-" 로 표현된다는건 뷰의 관심사인것 같아요.
현재의 콘솔 환경에선 "-", 웹 환경이라면 자동차의 위치에 맞는 이미지가 될수도 있지 않을까요?
| public class Printer { | ||
| Message message = new Message(); | ||
|
|
||
| private static String DEFAULT_SYMBOL = "-"; |
There was a problem hiding this comment.
사용되지 않는것 같네요 🙂
또한, 상수로 사용할땐 private static final을 사용해주세요!
| boolean reEnter = false; | ||
| private String inputLine = ""; |

java-racingcar 미션 제출합니다 !
좋은 하루 되세요 :)