-
Notifications
You must be signed in to change notification settings - Fork 1.2k
1주차 - Step2 자동차 경주 구현 #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} | ||
|
||
private List<Car> makeCars(int numberOfCars) { | ||
List<Car> cars = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cars를 일급콜렉션으로 구성하면 좋을거 같네요.
|
||
import java.util.List; | ||
|
||
public class RaceExecutor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RaceExecutor 객체의 역할이 모호한거 같아요.
자동차의 이동가능 여부는 Car 객체가 가지고 있어야 자연스러울거 같구요.
randomNumberGenerator 의존성을 주입하기 위해서 인자로 넣으신거라면 NumberGenerator 등의 interface를 작성하셔서 넘기시는게 좋을거 같습니다.
Cars 일급콜렉션까지 구성한다면 이 클래스는 없어질 수도 있겠네요.
for (Car car : this.cars) { | ||
moveIfPossible(car); | ||
} | ||
new OutputView(this.cars); // TODO: 결과화면을 여기서 생성하는 것이 어색한데 문제 없을지 궁금합니다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
도메인 모델에는 비즈니스로직만 남아있어야 합니다.
출력과 관련된 부분은 말씀하신대로 뷰모델에 위임하셔야 합니다.
현재 구조에서 변경하려면 각 trial별로 결과 데이터를 List 등에 담아서 리턴하는 것이 좋을 거 같네요.
final int numberOfTrials = scanner.nextInt(); | ||
inputNumberValidation(numberOfTrials); | ||
scanner.close(); | ||
System.out.println(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 부분들도 printEmptyLine()등의 메소드를 통해 의미를 분명히 드러내는 것이 좋다고 생각합니다.
public int getNumberOfTrials() { | ||
System.out.println(ASK_NUMBER_OF_TRIALS); | ||
final int numberOfTrials = scanner.nextInt(); | ||
inputNumberValidation(numberOfTrials); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두 메소드간에 중복코드가 있네요.
src/test/java/step2/CarTest.java
Outdated
@ParameterizedTest | ||
@ValueSource(ints = {1, 2, 3, 4, 5}) | ||
void 자동차가_주어진_거리만큼_이동한다(int numberOfMoves) { | ||
for(int i=0; i<numberOfMoves; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
공백 컨벤션 위반입니다. IDE에서 컨벤션을 자동으로 맞춰주는 shortcut이 있으니 확인해보세요.
intelliJ 는 option + command + l 입니다.
8.2 blank spaces 항목을 확인해보세요.
https://myeonguni.tistory.com/1596
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CarTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자동차 이동조건과 관련된 테스트가 없네요.
} | ||
|
||
public void raceExecute() { | ||
System.out.println("실행 결과"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
출력과 관련된 건 OutputView에 위임하는게 좋을거 같네요.
public CarRace(int numberOfCars, int numberOfTrials) { | ||
this.cars = makeCars(numberOfCars); | ||
this.numberOfTrials = numberOfTrials; | ||
this.raceExecutor = new RaceExecutor(this.cars); //TODO : RaceExcutor는 CarRace가 생성되어야만 필요하니까 이렇게 생성했는데 문제없을까요? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성자 내에서 생성하는 것과 관련된 물음이라면, 문제는 없다고 생각합니다.
다만, RaceExecutor에 cars를 전달하여 로직을 수행하는 것은 객체지향적이지는 않다고 생각합니다.
public class OutputView { | ||
private static final String POSITION_OF_CAR = "-"; | ||
|
||
public OutputView(List<Car> cars) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Car 객체를 OutputView에 직접 전달하면, 뷰모델에서 객체의 상태를 변경시킬 수 있지 않을까요.
뷰모델에는 Value Object만 넘기는 것이 좋다고 생각합니다.
src/test/java/step2/CarTest.java
Outdated
|
||
@BeforeEach | ||
void init() { | ||
car = new Car(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별다른 로직이 없다면 private Car car = new Car();
로 구현해도 되지 않을까요/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요!
몇가지 피드백 남겼으니 확인해보시고 궁금한 점 있으면 DM 남겨주세요.
자동차 객체의 이동조건에 대한 경계값 테스트가 없네요.
그리고 값을 받는 부분에서 유효성 검사를 해준다면, 이 부분에 대한 테스트도 유의미하다고 생각합니다.
|
||
@Test | ||
void 입력된_숫자만큼_자동차가_생성된다() { | ||
//TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static CarRace raceStart(int numberOfCars, int numberOfTrials) { | ||
numberOfCarsValidation(numberOfCars); | ||
numberOfTrialsValidation(numberOfTrials); | ||
return new CarRace(Cars.makeCars(numberOfCars)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정적 팩토리 메서드를 사용하셨네요! 👍
for (Car car : cars) { | ||
car.move(numberGenerator.getRandomNumber()); | ||
} | ||
return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일급 콜렉션은 불변성을 보장해야 합니다.
} | ||
|
||
public List<Car> getCars() { | ||
return cars; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DTO를 사용하지 않는다면 값을 getter하는 부분에서 read-only 혹은 불변객체로 리턴하는 것이 좋다고 생각합니다.
https://www.geeksforgeeks.org/collections-unmodifiablelist-method-in-java-with-examples/
this.cars = cars; | ||
} | ||
|
||
public List<Car> getCars() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method 순서에 대해서도 한번 고민해보세요
https://stackoverflow.com/questions/4668218/are-there-any-java-method-ordering-conventions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 반영하여 잘 작성해주셨네요! 👍
이번에 작성하지 못한 테스트코드는 추후에 꼭 진행해주세요~
몇가지 피드백 남겼으니 확인해보시고, 궁금한 점 있으면 DM 남겨주세요
이번 Step은 여기서 Merge할게요~
안녕하세요!
Step1에서 피드백 해주신 부분들 감사했습니다.
일정이 조금 촉박해서 Step1을 리팩토링하지는 못했습니다.
앞으로 이어질 단계들에서 적용해보겠습니다.
Step2에서는 테스트 코드를 많이 작성하지 못했습니다.
어떤 로직을 테스트해야할지 감이 잘 잡히지 않았습니다.
전체적으로 구조가 조잡하고 역할이 명확하지 않은 것 같아서
몇 가지를 제외하고는 질문을 따로 작성하지 않았습니다..
문제가 될만한 부분은 사소한 것이라도 간략하게라도 지적해주시면 감사하겠습니다!
그리고, 객체지향원칙 중에 일급 콜렉션을 사용하라는 부분이 있어 적용해보고 싶었는데, (실패했습니다ㅜ)
이번 구현에서 어떤 부분에 일급 콜렉션을 사용했으면 좋았을 지 힌트라도 주시면 감사하겠습니다!
바쁘신 와중에 좋은 피드백 감사합니다 👍 👍