Skip to content
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

Step4 - 자동차 경주 #4723

Open
wants to merge 2 commits into
base: sanghocho-pixel
Choose a base branch
from

Conversation

SanghoCho-pixel
Copy link

기능구현 완료하여 pr제출합니다.

감사합니다!

Copy link
Member

@nooose nooose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3단계 머지되기 전 작성된 PR 같아요
3단계 PR에 피드백 드린 부분 확인해 보시고
4단계 재요청 주시면 빠르게 확인하도록 할게요!

@SanghoCho-pixel
Copy link
Author

SanghoCho-pixel commented May 23, 2023

기능구현에 추가하여 step3에서 review해주신 부분 반영했습니다.

지난 리뷰에서
if(moveStrategy.isSuccess()) { car.move(); }

car.move(moveStrategy)
의 차이점에 대해 고민해보라 하셨는데요,

  • 전자처럼 RacingGame의 코드에서 MoveStrategy를 가지고 사용하는 형태라면, �Car객체 테스트 시에 MoveStrategy를 포함시킨 테스트는 불가능할 것 같습니다. Strategy에 따른 테스트 코드를 짜려면 RacingGame의 테스트 코드에서 진행해야 합니다.

  • 반면 Car객체가 MoveStrategy를 인자로 받아 사용하는 형태라면, 주입하는 Strategy에 따른 테스트를 진행해볼 수 있습니다.

어떤것이 더 유리한 방법인가에 대해서는 아직 잘 모르겠습니다. Car객체에서 Strategy를 포함하여 테스트할 수 있는게 장점일까요?

@nooose
Copy link
Member

nooose commented May 23, 2023

  • 반면 Car객체가 MoveStrategy를 인자로 받아 사용하는 형태라면, 주입하는 Strategy에 따른 테스트를 진행해볼 수 있습니다.

어떤것이 더 유리한 방법인가에 대해서는 아직 잘 모르겠습니다. Car객체에서 Strategy를 포함하여 테스트할 수 있는게 장점일까요?

네 제대로 이해하신 것 같아요!
Car마다 다른 전략을 사용할 수도 있기 때문에 이전 방식을 사용했다면 Car 전체가 같은 전략을 사용할 수 밖에 없게 됩니다.
그렇게 되면 추후 유지보수 관점에서 자유롭지 못한 코드가 될 것 같아요
이런 이유로 Car가 전략을 주입받아 사용할 수 있도록 변경하는 것이 맞다고 생각해요

Copy link
Member

@nooose nooose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 피드백 반영까지 해주시고 잘 구현해 주신 것 같아요
그런데 요구사항에 미치지 못한 부분들이 있네요 😭
확인해 보시고 재요청 부탁드립니다.

Comment on lines +29 to +37
for (Car car : carList) {
if (car.getPosition() > maxPosition) {
maxPosition = car.getPosition();
winnerList.clear();
winnerList.add(car);
} else if (car.getPosition() == maxPosition) {
winnerList.add(car);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 코드를 보시면 depth가 2단계(for문안에 if 블록)이고 else 키워드를 사용하고 있어요

image

프로그래밍 요구사항에 맞게 변경해 볼까요?

Comment on lines +41 to +45
public void play() {
for (Car car : carList) {
car.move(moveStrategy);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intellij를 사용하고 계신가요? 3단계에 있었던 요구사항이었는데요
단축키를 사용하면 쉽게 컨벤션을 맞출 수 있습니다!

image

Suggested change
public void play() {
for (Car car : carList) {
car.move(moveStrategy);
}
}
public void play() {
for (Car car : carList) {
car.move(moveStrategy);
}
}


public class RacingGame {

private final List<Car> carList = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final List<Car> carList = new ArrayList<>();
private final List<Car> cars = new ArrayList<>();

자료구조에 의존하지 않는 변수명을 사용하는 것을 권장하고 있습니다.
그래서 보통 컬렉션을 담고있는 변수명은 주로 복수형으로 표현하고 있어요
사실 거의 변경이 없겠지만 자료구조가 변경된다는 이유로 변수명이 함께 변경되는 것은 좋지 않은 것 같아요

Comment on lines +9 to +10
private static final String POSITION_MARK = "-";
public void printCars(List<Car> cars) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가독성을 위해 변수 필드 부분과 메서드를 개행으로 분리하는 것이 좋습니다.

    private static final String POSITION_MARK = "-";

    public void printCars(List<Car> cars) {

import java.util.ArrayList;
import java.util.List;

public class RacingGame {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RacingGame도 도메인으로 볼 수 있을 것 같아요
그런데 테스트 코드가 없네요 😭

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패키지 위치도 같이 고려해보시면 좋을 것 같아요
RacingGame과 move 패키지 내 클래스들도 domain의 영역이지 않을까요?

추가로 InputView, ResultView 부분도 view 같은 패키지로 이동시켜보면
구조를 쉽게 파악할 수 있을 것 같습니다.

Comment on lines +29 to +37
for (Car car : carList) {
if (car.getPosition() > maxPosition) {
maxPosition = car.getPosition();
winnerList.clear();
winnerList.add(car);
} else if (car.getPosition() == maxPosition) {
winnerList.add(car);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직이 너무 비효율적인 것 같아요

  1. 자동차 리스트에서 maxPosition을 구한다.
  2. maxPosition인 Car만 추출해서 반환

이렇게만 작성해도 훨씬 읽기 좋은 코드가 될 것 같습니다 😄

Comment on lines +12 to +13
public boolean isSuccess() {
final Random random = new Random();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSuccess()가 호출될 때 마다 Random 객체를 새로 생성할 필요가 있을까요?
재사용할 수 있도록 변경할 수 있을 것 같아요

Comment on lines +8 to +9
private final String name;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요구사항 중 자동차 이름은 5자를 초과할 수 없다.가 있었어요

해당 부분도 구현해야 하지 않을까요?
이에 대한 테스트 코드도 있으면 좋겠어요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants