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

[럿고] 자동차 경주 게임 제출합니다. #2

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

ksy90101
Copy link

오랜만에 하니깐 재미있네요 ㅎㅎ
전체적으로 부족한 코드인데 마음껏 까주세요 ㅎㅎ
잘 부탁드려요!

Copy link
Member

@hongbin-dev hongbin-dev left a comment

Choose a reason for hiding this comment

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

안녕하십니까 럿고.
어제 리뷰 남기기로했는데ㅠ 잊고있었네요.
구현하느라 고생하셨습니다. 개인적인 의견 남겨봅니다.
감사합니다.✌

@@ -0,0 +1,7 @@
package domain.car;

@FunctionalInterface
Copy link
Member

Choose a reason for hiding this comment

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

👍👍

Comment on lines 4 to 6
public interface CarMoveStrategy {

int move();
Copy link
Member

Choose a reason for hiding this comment

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

interface만 봤을 때 이동하는 전략일까? 라는 생각이 드는 네이밍이에요.
move의 메서드이름도 integer를 생성하는 일만 하고있는데 move가 맞을까 생각이 듭니다.

Copy link
Author

Choose a reason for hiding this comment

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

네이밍을 조금 더 고민했어야 하는데, ㅎㅎ 감사합니다~

public class RacingController {

private static final String SPLIT_DELIMITER = ",";
private static final CarMoveStrategy carMoveStrategy = () -> (int)(Math.random() * 10);
Copy link
Member

Choose a reason for hiding this comment

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

10에 대한 상수를 포장해도 좋을 것 같네요.

Comment on lines 40 to 44
OutputView.runResultGuide();
for (int i = 0; i < gameCount.getGameCount(); i++) {
cars.moveCars(carMoveStrategy);
OutputView.printRunResult(cars.getCars());
}
Copy link
Member

Choose a reason for hiding this comment

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

for-each문으로 바꿀수있는 방법은 없을까요?

Copy link
Author

Choose a reason for hiding this comment

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

getCount.getGameCount()가 int인데 어떻게 해야 하나요.. ㅠㅠ 정말 몰라서 물어봅니다 ㅠㅠ

Comment on lines 47 to 54
private List<Car> createCars(final String inputCarNames) {
List<String> carNames = Arrays.stream(inputCarNames.split(SPLIT_DELIMITER))
.collect(Collectors.toList());

return carNames.stream()
.map(Name::new)
.map(name -> new Car(name, PositionFactory.of(0)))
.collect(Collectors.toList());
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 List<Car> createCars(final String inputCarNames) {
List<String> carNames = Arrays.stream(inputCarNames.split(SPLIT_DELIMITER))
.collect(Collectors.toList());
return carNames.stream()
.map(Name::new)
.map(name -> new Car(name, PositionFactory.of(0)))
.collect(Collectors.toList());
private Cars createCars(final String inputCarNames) {
List<String> carNames = Arrays.stream(inputCarNames.split(SPLIT_DELIMITER))
.collect(Collectors.toList());
return carNames.stream()
.map(Name::new)
.map(name -> new Car(name, PositionFactory.of(0)))
.collect(collectingAndThen(toList(), Cars::new));

이렇게 가져가도 가독성이 좋을 것 같아요.

Comment on lines 9 to 11
protected Position(final int position) {
this.position = position;
}
Copy link
Member

Choose a reason for hiding this comment

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

패키지레벨을 더 디테일하게 만들고, default 접근지정자는 어떨까요?

Comment on lines 9 to 22
private static final List<Position> positions = IntStream.range(0, 11)
.mapToObj(Position::new)
.collect(Collectors.toList());

private PositionFactory() {

}

public static Position of(int positionValue) {
return positions.stream()
.filter(position -> position.getPosition() == positionValue)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("나올 수 없는 위치 입니다. position = " + positionValue));
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. 10개밖에 없어서 큰 차이는 아니지만 Map<Integer, Position> map 으로 갖고있으면, of에서 순회하면서 찾는것보다 빠를것 같아요.

  2. Intstream.rangeClosed(0,10) 이 가독성이 더 좋을 것 같군요

Copy link
Author

Choose a reason for hiding this comment

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

  1. 다음에 고려해볼께요. 절대로 귀찮아서가 아닙니다!
  2. 그렇네요~

Comment on lines +9 to +11
private static final List<GameCount> gameCounts = IntStream.range(2, 11)
.mapToObj(GameCount::new)
.collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

stream.rangeClosed() 사용을 추천드리고, 상수 값을 활용해볼까요?

Comment on lines +25 to +31
private static void validateNotNumber(final String gameCount){
try{
Integer.parseInt(gameCount);
}catch (NumberFormatException e){
throw new NumberFormatException("숫자만 입력이 가능합니다. gameCount = " + gameCount);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

👍👍

Comment on lines 28 to 30
String winner = winners.stream()
.map(Car::getName)
.collect(Collectors.joining(", "));
Copy link
Member

Choose a reason for hiding this comment

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

", "도 상수로 포장해볼까요?

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.

2 participants