Skip to content

[자동차 경주] 배진호 미션 제출합니다. #77

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

Merged
merged 8 commits into from
Feb 18, 2025

Conversation

BaeJinho4028
Copy link

@BaeJinho4028 BaeJinho4028 commented Feb 9, 2025

처음에는 Spy 객체를 활용하여 테스트를 작성하려 했습니다. 하지만 Game 클래스의 생성자가 carNames를 받고 내부에서 cars를 선언하는 구조 때문에 한계를 마주했습니다. 그러다 "Car들의 위치 반환이 꼭 Game에서 이루어져야 할까?" 라는 고민이 들었고, 이를 해결하기 위해 CarGroup 클래스를 도입했습니다. CarGroup은 생성자에서 Cars를 직접 받도록 하여, 기존의 Spy 객체 방식으로도 테스트를 처리할 수 있게 수정하였습니다.

그런데 주변 분들이 미션을 진행하는 방식을 살펴보니 저만 Spy 객체를 활용하고 있었습니다. 다른 방법이 있을까 찾아보던 중, NumberProvider 인터페이스를 활용한 다형성 방식을 발견했고, 이를 적용하면 보다 유연한 테스트가 가능하다는 점이 흥미로웠습니다. 이에 따라 Spy 객체를 사용하지 않는 방향으로도 구현을 시도해 보았습니다.

또한, MVC 패턴 기반으로 리팩터링하면서 view 패키지가 domain 패키지 객체에 의존할 수는 있지만, 반대로 domain 패키지가 view 패키지에 의존해서는 안 된다는 점이 흥미로웠습니다. 다행히 3단계에서 이미 4단계의 일부를 적용한 상태였기에, 불필요한 의존성을 줄이는 작업만 진행하며 리팩터링을 마무리할 수 있었습니다.

현재 딱히 궁금한 점은 없지만, 더 나은 방향으로 개선할 방법이 있을지 고민됩니다.

(역시 단위 테스트 작성 시 Spy 객체 활용이 유용한 것 같습니다. 기존 객체의 상태를 유지하면서 특정 메서드가 정확히 몇 번 호출되었는지 검증하는 기능이 있어서.)

Copy link

@Soundbar91 Soundbar91 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 9 to 10
private final static int MOVE_CONDITION = 4;
private final static int MAX_NAME_LENGTH = 5;

Choose a reason for hiding this comment

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

final staticstatic final 둘 다 차이는 없지만, 자바 컨벤션 상으로 static final를 사용한다고 합니다 👍

Copy link
Author

Choose a reason for hiding this comment

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

저도 보통 그렇게 쓰는데 뭔가 뇌빼고 하다가 저렇게 됐네요. 꼼꼼한 리뷰 감사해욤


public Game(String carNames, int tryCount) {
validateTryCountIsPositive(tryCount);
this.carGroup = new CarGroup(createCars(carNames), new RandomNumberProvider());
Copy link

@Soundbar91 Soundbar91 Feb 13, 2025

Choose a reason for hiding this comment

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

생성자 인자로 RandomNumberProvider을 주입 받는 방식에 대해서 진호님은 어떻게 생각하시나요 !

Copy link
Author

Choose a reason for hiding this comment

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

저도 좋은데, MVC 패턴으로 리팩터링 후의 main 메소드 예시 와 코드를 똑같이 두고싶은 고집때문에 지금처럼 했어요 ㅋㅋㅋ. 수정하겠습니다

this.tryCount = tryCount;
}

private List<Car> createCars(String carNames) {

Choose a reason for hiding this comment

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

게임이라는 클래스에 자동차를 만드는 메소드가 있는 것이 개인적으로 애매하다고 생각이 들었어요 !

게임에 참여하는 자동차 생성을 담당하는 클래스를 만들어서 책임을 분할하는 것에 대해 진호님은 어떻게 생각하시나요 ??

Copy link
Author

Choose a reason for hiding this comment

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

좋은 생각이네요. 그렇게 수정하겠습니다!

@boorownie boorownie merged commit 2d15532 into next-step:baejinho4028 Feb 18, 2025
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.

3 participants