Conversation
hyukjin-lee
left a comment
There was a problem hiding this comment.
고생하셨습니다 ~
Winner 에 대한 로직을 분리시키신거 👍
피드백 조금 남겼으니 확인 후 반영해주시면 감사하겠습니다
몇개 안되니 반영 완료해주시면 다른 부분에 대한 피드백 추가로 드리겠습니다 ~
| public int position; | ||
|
|
||
| public int addPosition() { | ||
| return this.position++; |
There was a problem hiding this comment.
addPosition 도 데이터 변경에 대한 설명이 되는 것 같지만,
run 이라는 행위를 표현하는 단어로 메서드명을 지어보면 어떨까요?
추후에 자동차 기본 이동 조건이 +2 로 바뀐다고 가정 했을 때
addPosition 이면 해당 메서드를 사용하는 입장에서 position+1 일 것 같다는 생각이 드는데
run 으로 추상화 되어있으면 +2 를 하든 +1 을 하든 자동차가 이동한다는 행위를 나타내서 혼동이 없을 것 같습니다 ~
There was a problem hiding this comment.
메서드명을 지을 때 조건 변경의 가능성을 꼭 고려하도록 하겠습니다! 단번에 이해되는 좋은 예시 제시해주셔서 감사합니다.
src/mission1/Car.java
Outdated
| System.out.print(this.name + " : "); | ||
| for (int i = 0; i < this.position; i++) { | ||
| System.out.print("-"); | ||
| } |
There was a problem hiding this comment.
결과를 보여주는 View 의 역할은 ResultView 에 위임하면 어떨까요?
There was a problem hiding this comment.
추후에 콘솔이 아닌 GUI 프로그램으로 확장된다고 했을 때 Car 이라는 pure 해야하는 모델 클래스가 더럽혀지지 않을까요~?
There was a problem hiding this comment.
GUI 프로그램으로 확장될 경우도 고려해야 한다는 점 명심하겠습니다!
src/mission1/GameWinner.java
Outdated
| import java.util.ArrayList; | ||
|
|
||
| public class GameWinner { | ||
| public ArrayList<String> findWinner(Car[] car) { |
There was a problem hiding this comment.
조슈아 블로크의 effective java 에는 '객체는 인터페이스를 사용해 참조하라.'
라는 부분이 있습니다.
한번 읽어보시고 개선해보시면 좋을 것 같아요 ~
jaehun2841.github.io/2019/03/01/effective-java-item64/#%EC%9C%A0%EC%97%B0%ED%95%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B3%80%EC%88%98
There was a problem hiding this comment.
배열 사용을 지양하고 List 로 최대한 넘겨받으면 어떨까요?
There was a problem hiding this comment.
자료 감사합니다👍 List인터페이스 구현해보도록 하겠습니다.
src/mission1/Main.java
Outdated
| for (int i = 0; i < time; i++) { | ||
| racingGame.raceByTime(car); | ||
| resultView.showResultByTime(car); | ||
| System.out.println(); |
There was a problem hiding this comment.
Main 에 콘솔 출력하는 코드를 없애보면 어떨까요~?
src/mission1/RacingGame.java
Outdated
| import java.util.Random; | ||
|
|
||
| public class RacingGame { | ||
| static final int RANDOM_RANGE = 10; |
There was a problem hiding this comment.
접근제어자를 생략하신 이유가 있을까요? 생략하면 어떤 접근제어자가 붙을까요?
There was a problem hiding this comment.
메서드의 접근제어자에 몰두한 나머지 변수의 접근제어자는 미처 고려하지 못했던 것 같습니다. 생략할 경우 default 접근제어자가 되어 해당 패키지 내에서 접근가능하게 합니다. 여기에서는 해당 클래스 내에서만의 접근이 필요하므로 private를 붙여 수정하겠습니다.
| public int position; | ||
|
|
||
| public int addPosition() { | ||
| return this.position++; |
There was a problem hiding this comment.
메서드명을 지을 때 조건 변경의 가능성을 꼭 고려하도록 하겠습니다! 단번에 이해되는 좋은 예시 제시해주셔서 감사합니다.
src/mission1/Car.java
Outdated
| System.out.print(this.name + " : "); | ||
| for (int i = 0; i < this.position; i++) { | ||
| System.out.print("-"); | ||
| } |
There was a problem hiding this comment.
GUI 프로그램으로 확장될 경우도 고려해야 한다는 점 명심하겠습니다!
src/mission1/RacingGame.java
Outdated
| import java.util.Random; | ||
|
|
||
| public class RacingGame { | ||
| static final int RANDOM_RANGE = 10; |
There was a problem hiding this comment.
메서드의 접근제어자에 몰두한 나머지 변수의 접근제어자는 미처 고려하지 못했던 것 같습니다. 생략할 경우 default 접근제어자가 되어 해당 패키지 내에서 접근가능하게 합니다. 여기에서는 해당 클래스 내에서만의 접근이 필요하므로 private를 붙여 수정하겠습니다.
src/mission1/GameWinner.java
Outdated
| import java.util.ArrayList; | ||
|
|
||
| public class GameWinner { | ||
| public ArrayList<String> findWinner(Car[] car) { |
There was a problem hiding this comment.
자료 감사합니다👍 List인터페이스 구현해보도록 하겠습니다.
hyukjin-lee
left a comment
There was a problem hiding this comment.
잘 수정해주셨네요 ! 2차 피드백 간단하게 드립니다 ~
| @@ -0,0 +1,8 @@ | |||
| public class Car { | |||
| public String name; | |||
| public int position; | |||
There was a problem hiding this comment.
car 의 상태가 외부에서 접근가능한 public 인데요~
private 으로 변경해주셔야할 것 같습니다 !
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class GameWinner { |
There was a problem hiding this comment.
Winner 객체에서 들고 있으면 좋을만한 상태(필드 변수)들을 정의하고 책임을 부여해보면 어떨까요?
|
|
||
| public class GameWinner { | ||
| public List<String> findWinner(List<Car> cars) { | ||
| int max = cars.get(0).position; |
There was a problem hiding this comment.
객체지향에서는 객체의 상태에 직접 접근해서는 안됩니다.
private 으로 변경하시면 getter 로 변경하셔야할 것 같아요~
| List<String> winnerList = new ArrayList<>(); | ||
| for (Car car : cars) { | ||
| addWinnerList(car, max, winnerList); | ||
| } | ||
| return winnerList; |
There was a problem hiding this comment.
java8 의 stream api 를 적용해보면 어떨까요~?
| import java.util.List; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class InputView { |
There was a problem hiding this comment.
InputView 에는 상태값이 없는데요,
util 클래스로 활용될 수 있을 것 같아서 모든 메서드들에 static 을 활용해보시면 어떨까요?
| private static final int RANDOM_RANGE = 10; | ||
| private static final int MIN_MOVE_STANDARD = 4; | ||
|
|
||
| public void raceByTime(List<Car> cars) { |
There was a problem hiding this comment.
random 으로 인해 게임의 핵심 pulbic 메서드가 테스트 불가능해졌는데
어떻게 개선해 볼 수 있을까요?
Uh oh!
There was an error while loading. Please reload this page.