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주차] 로또 - 클린코드 #65

Open
wants to merge 34 commits into
base: sansan20535
Choose a base branch
from

Conversation

sansan20535
Copy link

안녕하세요!! 바쁘신 스케줄 중에도 시간 내어 리뷰해주셔서 정말 감사합니다 : ) 많이 배우도록 하겠습니다..!!

🚀 기능 구현 🚀

  • README.md를 참고해주시면 감사할 것 같습니다 : )

❓ 질문 사항 ❓

  • 테스트를 하면서 enum 클래스의 필드 값이 변화되는데, 이것이 다른 테스트의 결과에도 영향을 가져와 @beforeeach로 초기화를 하기로 했습니다. 그러는 과정에서 enum클래스는 상속이 되지 않아 테스트용 메소드를 하나 만들어놓았는데 이에 대한 해결 방법이 궁금합니다..!!

🔧 수정 사항 🔧

  • 이번에 시간이 많이 부족해서 예외처리에 대해 신경을 쓰지 못했습니다. 이후 리뷰반영과 함께 리팩토링하겠습니다.

Copy link

@kokodak kokodak left a comment

Choose a reason for hiding this comment

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

안녕하세요 의진님! 미션 정말 고생 많으셨습니다 👏

객체 분리에 신경을 쓰신게 느껴졌고, 테스트도 꼼꼼하게 작성해주신 것이 너무 좋았어요.

남기신 질문 사항들은 코멘트로 남겨두었고, 그외에 전반적인 리뷰를 코멘트로 남겨두었어요.

PR 본문에 남겨주셨듯이, 예외 처리도 추후에 추가되면 더 완성도 있는 코드가 될 것 같아요. 예외 처리까지 파이팅입니다 😄

Comment on lines +7 to +9
public class InputFromUser {

private static final Scanner scanner = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

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

Scanner를 이용한 입력 부분을 따로 분리해주셨군요! InputView가 존재하지만, 이를 한번 더 분리해주신 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

저는 '사용자 입력'과 '입력문구 출력'이라는 역할을 분리해서 보고 싶었습니다!! 그리고 이후 입력단계에서 잘못된 입력에 대해서 예외처리를 쉽게 할 수 있도록 하기 위해서 이렇게 분리했습니다!!

@@ -0,0 +1,25 @@
package view;
Copy link

Choose a reason for hiding this comment

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

저 개인적으로는, view 계층은 사용자와 가장 맞닿아 있는 곳이라 생각하는데요! 의진님이 생각하신 view 패키지의 역할은 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

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

저는 view 패키지의 역할은 사용자에게 정보를 제공하는 패키지라고 생각합니다!! 사용자가 어떤 행동을 해야하고, 그에 따라 어떤 결과를 얻을 수 있는지 정보를 제공하는 패키지라고 생각합니다 : )

@@ -0,0 +1,32 @@
package util;
Copy link

Choose a reason for hiding this comment

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

util 패키지는 무엇을 담을 수 있는 패키지인가요? 어쩌면 이것저것 다 담을 수 있는 만능 패키지가 될 수도 있을 것 같다는 우려가 있어요.

패키지를 나누는 이유가 무엇인지 고민해보면 좋을 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

저도 이번에 util에 대해서 고민을 많이 해보았는데... 프로그램 전체에 걸쳐서 필요한 기능을 util 패키지에 넣는 것이 맞는 것 같다고 생각했습니다!!(ex : 로또 번호 변환 -> 우승로또 입력, 수동로또 입력에 사용 등)

@@ -0,0 +1,54 @@
# 🚀1단계 - 로또 자동구매🚀
Copy link

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.

네 있습니다! 이전에는 이 기능, 저 기능 순서없이 구현하다보니 나중에 보면 주석이 있음에도 제가 이해하기 힘든 코드가 많았습니다. 하지만 이렇게 요구 사항과 구현 사항을 정리했을 때 제가 의도한 대로 코드를 작성했는지 쉽게 볼 수 있었고, 이후 추가적인 구현기능이 있더라도 비교적 쉽게 추가할 수 있었던 것 같습니다 : )


public class LottoCalculator {

private static final int LOTTO_COST = 1000;
Copy link

Choose a reason for hiding this comment

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

로또 가격을 상수로 추출해 주셨군요! 적절한 이름을 붙여주셔서, 코드를 읽는 입장에서 1000 이라는 숫자의 의미를 이해하는데 수월했습니다 👍

로또 가격에 대한 관리 포인트를 한 곳으로 줄인다는 관점에서도 좋은 것 같아요.

}

public boolean checkBonusNumber(final WinningLotto lastWeekWinnerLotto, final Lotto lotto) {
return lotto.getLottoNumber().contains(lastWeekWinnerLotto.getBonusNumber());
Copy link

Choose a reason for hiding this comment

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

위의 리뷰와 동일한 맥락입니다.
https://mangkyu.tistory.com/147

Copy link
Author

Choose a reason for hiding this comment

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

여기도 객체의 역할로 정할 수 있었네요! 감사합니다 : )

final int passiveLottoCount = 2;

//when
final int result = lottoCalculator.calculateAutoLottoCount(buyingCosts, passiveLottoCount);
Copy link

Choose a reason for hiding this comment

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

테스트 작성 시에, 실제로 나온 값에 대한 네이밍은 관례적으로 actual 이라는 이름을 붙이는 것 같아요. 네이밍은 정답이 없는 분야이니, 적당히 참고해주시면 될 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

아하! 관례를 따라가는 것이 이후 좋은 영향이 있을 거 같습니다 감사합니다 : )

List<Integer> result = LottoNumberConvertor.convertLottoNumbers(lottoNumbers);

//then
Assertions.assertThat(result).usingRecursiveComparison().isEqualTo(expected);
Copy link

Choose a reason for hiding this comment

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

테스트의 짬이 느껴지는데요..?

Assertions.assertThat(WinningLottosStatus.of(correctCount, isSecondPrize).getLottoCount()).isEqualTo(expected);
}

static Stream<Arguments> generateData() {
Copy link

Choose a reason for hiding this comment

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

👍 👏👏
@ParameterizedTest를 잘 활용해주셨네요.. 의진님 고수시군요

Copy link
Author

Choose a reason for hiding this comment

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

아닙니다... 모두 보고 배운 겁니다 너무 감사합니다 : )

Comment on lines +17 to +20
@BeforeEach
public void initializeWinningLotto() {
WinningLottosStatus.initialize();
}
Copy link

@kokodak kokodak Oct 4, 2024

Choose a reason for hiding this comment

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

이 부분에 대한 생각을 남겨보자면,

일단, 매번 초기화를 해줘야 하는 이유부터 파악을 해야겠죠. 가장 근본적인 이유는, 싱글턴으로 존재하는 Enum 인스턴스에 lottoCount 라는 변화하는 값을 필드로 넣은 것이 문제의 출발점입니다.

그렇다면 Enum 안에 있는 lottoCount를 제거하면 되지 않을까요? 이를 계산해서 저장하는 곳을 따로 만드는 것이 좋을 것 같아요.

추가로, Enum의 역할에 대해 다시 생각해 볼 필요가 있는 것 같아요. Enum에 변수 값이 들어간 순간부터, 이를 더 이상 상수라는 개념으로 보기 어려울 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

정확하게 말씀해 주신 것 같습니다.. Enum은 변하지 않는 상수여야 하는데 업데이트를 하는 것이 맞는 것인가 생각을 했었습니다. 답이 의외로 간단했군요..! 감사합니다, 수정해보도록 하겠습니다 : )

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