Skip to content

Conversation

baaamk
Copy link

@baaamk baaamk commented Apr 8, 2025

객체에 대해서 전에 몰랐던 사실을 투영하기 위해서 객체에 책임에 대해서 좀 더 생각하면서 구현했습니다.
예를 들면 처음엔 RacingCar에서 우승자를 찾게 책임을 부여했는데, 레이싱카가 우승자를 찾는게 맞나? 하는 생각에서 Race 즉, 경기가 우승자를 찾게 책임을 부여했습니다.
초기에 구상은 frontController 을 사용해보자 햇지만, 객체에 더 집중하라는 조언을 듣고 바꾸었습니다.
이펙티브 자바는 첫장에 정적 팩토리 메서드 아이템을 사용했습니다. equals 와 hashcode를 적용하려 했지만 좀 아직 이해가 가지 않는 부분이 있어 다음 미션때 더 반영해보도록 하겠습니다.

또 초기에는 Map을 이용해서 라운드 마다의 결과를 Map에 key value로 저장하려 했지만 동일한 인스턴스를 써서 최종값이 산출되는 일이 있었습니다. 이걸 해결하기 위해 스냅샷을 고려했으나, 그러기엔 너무 복잡해 진다는 판단이 들어 Controller에서 for로 간단하게 해결하도록 바꾸었는데 괜찮은 건지 궁금합니다.

get 사용을 줄이고 TDA 원칙 준수하려 했으나 잘 되었는지 모르겠습니다.

피드백.. 발표 끝나고도 좋으니 해주시면 감사하겠습니다!

baaamk added 29 commits April 5, 2025 23:33
boolean 반환값으로 RacingCar 에서 움직이도록 했습니다.
일급 컬렉션을 사용하기 위해 RacingCars 클래스 생성했습니다.
1. 레이스 시작 메서드 구현
2. position 구하는 메서드 구현
1. 파라메터 추가
2. input으로 들어올 횟수만큼 반복 기능 구현
1. 라운드에 경기 paly 책임 부여 TDA원칙 준수
2. 정적 팩토리 메서드
3. getRoundResult 필요한지 고민..
1. 결과 비교 책임 부여
2. stream Api filter 사용.
우승자들만 모은 리스트 이기 때문에 새로운 RacingCars 객체 생성
1. Round 에 결과 위임했기 때문에 return 수정
1. 에러 메세지
2. 매직 넘버
1. DTO 사용하도록 유도
리턴 리스트 변경 불가능하다하여 toUnmodifiableList() 에서 수정
@baaamk baaamk self-assigned this Apr 8, 2025
baaamk added 3 commits April 9, 2025 19:11
상수 클래스 삭제 후 상수는 클래스에서 관리하도록 변경
1. 불변 리스트로 초기화 하게 변경.
getRacingCars() 반환값도 이미 리스트가 불변이기 때문에 새로 리스트 생성하지 않고 그대로 리스트 반환
Copy link

@KoSeonJe KoSeonJe 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 +3 to +16
- [X] RacingCar 클래스
- [X] name 길이 검증 메서드
- [X] name 존재 검증 메서드
- [X] name 공백 검증 메서드
- [X] position move 메서드
- [X] RacingCar을 리스트로 한 RacingCars 클래스
- [X] 이름 중복 검증 메서드
- [X] 이름 목록 Empty 검증 메서드
- [X] 레이스 참가 레이싱카 생성 팩토리 메서드 //이펙티브 자바
- [X] 게임을 담당할 Race 클래스 생성
- [X] 게임 시작 메서드
- [X] position 비교 메서드
- [X] 이곳에서 경기 결과 나오는게 맞다 판단하여 findResult, getWinner 메서드 생성
- [X] 게임 시도 숫자 검증할 TryNumber 클래스

Choose a reason for hiding this comment

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

객체간 의존성을 그림으로 그리면 어떤 관계를 가지고 있는지 쉽게 알 수 있을 것 같아요

private OutputView outputView() {
return new OutputView();
}

Choose a reason for hiding this comment

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

Suggested change

필요없는 줄바꿈 제거해주세요

public class AppConfig {

public Controller controller() {
return new RaceController(inputView(),outputView());

Choose a reason for hiding this comment

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

Suggested change
return new RaceController(inputView(),outputView());
return new RaceController(inputView(), outputView());

컨벤션!


@Override
public void execute() {
RacingCars racingCars = inputName();

Choose a reason for hiding this comment

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

메서드명을 적절히 수정해주면 좋을 것 같아요!
inputName이라는 행위에 RacingCars를 생성하고 반환하는 것은 적절하지 않은 것 같아요!

Comment on lines +54 to +59
private List<RacingCar> createRacingCars() {
return Arrays.stream(inputView.inputName().split(","))
.map(String::trim)
.map(RacingCar::create)
.collect(Collectors.toList());
}

Choose a reason for hiding this comment

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

CarName 컬렉션을 만드는 행위와
CarName들로 RacingCar인스턴스를 생성하는 행위를 분리하면 가독성이 더 좋아질 것 같아요



private void validateDuplicateName(List<RacingCar> racingCars) {
if (racingCars.size() != racingCars.stream().distinct().count()) {

Choose a reason for hiding this comment

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

이름이 같다고 같은 객체임을 구현해주지 않았는데, 제대로 동작하나요!?

}

public RacingCars startRace() {
return RacingCars.create(racingCars.moveAll());

Choose a reason for hiding this comment

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

moveAll에서 새로운 RacingCars를 생성한 뒤 반환하는 것은 어떤가요?

return new RacingCars(userInput);
}

public List<RacingCar> moveAll() {

Choose a reason for hiding this comment

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

컬렉션을 그대로 반환한다면 일급 컬렉션을 생성한 의미가 떨어지지 않을까요?

Comment on lines +6 to +9
public static final int MIN = 0;


private final int tryNumber;

Choose a reason for hiding this comment

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

Suggested change
public static final int MIN = 0;
private final int tryNumber;
public static final int MIN = 0;
private final int tryNumber;

줄바꿈도 컨벤션!

Comment on lines +16 to +18
public static TryNumber from(int tryNumber) {
return new TryNumber(tryNumber);
}

Choose a reason for hiding this comment

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

다른 객체는 create인데, 이 객체는 from이네요!
통일해주면 사용하기 편할 것 같아요~

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