-
Notifications
You must be signed in to change notification settings - Fork 72
[LBP] 윤준석 로또 미션 2-5단계 제출합니다. #89
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
base: junseok0304
Are you sure you want to change the base?
Conversation
commit suggest Co-authored-by: Ji_Yun <[email protected]>
# Conflicts: # src/main/java/model/Lotto.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 준석 👋
이번 미션 갑자기 난이도가 올라가서 많이 어려웠을 거 같아요!
그래도 MVC를 준수하기 위해 많이 노력하신 것 같습니다 고생하셨어요 👍
질문주신 부분에 대해서는 리뷰 코멘트로 남겼습니다!
요구사항인 일급컬렉션과 원시 값 포장도 학습하시고 적용해보시면 좋을 것 같아요 😉
추가적으로 궁금하신 점이 있다면 편하게 질문해주세요.
@@ -0,0 +1,18 @@ | |||
package config; | |||
|
|||
public enum LottoConstants { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum 활용 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다!
|
||
import java.util.*; | ||
|
||
public class LottoValidator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LottoConstants
를 정의했지만 Validator
에서 사용하지 않은 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 Validator 클래스가 유틸리티 성격을 띠고 있지만, Lotto와 LottoMachine에서도 자체적으로 검증을 하고 있어서 중복되는 코드가 많아 보여요 🤔
도메인 계층에서 검증을 수행하고 있는데, Controller
에서 한 번 더 검증하는 이유가 있을까요?
도메인에서 검증하는 방식과 Validator
클래스를 사용하는 방식 각각의 장단점을 비교해 보면 좋을 것 같아요. 그 후에 리팩토링 방향을 고민해보시면 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예외메시지 출력을 위해서였지만
중복되는 코드가 생기는 이슈가 있었네요,
validator에서 사전 입력 검증을 하도록 하고
도메인 내부에서 검증 로직을 메서드로 정리해서 재사용하는 방식도 괜찮을 것 같습니다!
List<Integer> numbers = Arrays.stream(input.split(",")) | ||
.map(String::trim) | ||
.map(Integer::parseInt) | ||
.toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 메서드의 길이가 요구사항(10라인 제한)을 초과한 것 같아요. 검증 로직이 추가되면 더 길어질 가능성도 있어 보이네요 🤔
이 메서드에서는 입력을 나누는 역할과 검증하는 역할을 함께 하고 있는데, 혹시 입력을 나누는 로직이 다른 곳에서도 필요할 가능성이 있을까요? 만약 그렇다면 별도 메서드로 분리하면 어떤 장점이 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
입력값을 나누는 로직과 검증하는 로직을 분리하면 재사용성을 재고할 수 있고
테스트 코드 작성시에도 이점이 있을 것 같습니다!
import java.util.stream.IntStream; | ||
|
||
public class LottoMachine { | ||
private static final int LOTTO_PRICE = LottoConstants.LOTTO_PRICE.getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 LottoConstants
에서 값을 불러올 수 있는데, 상수를 한 번 더 감싼 이유가 있을까요?
이렇게 하면 상수의 계층이 하나 더 늘어나서 오히려 가독성이 떨어질 수도 있을 것 같아요. 준석님은 어떻게 생각하세요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇네요ㅜㅜ LottoConstants에서 값을 불러와서 사용하는 방식이 나을 것 같습니다!
가독성 측면에서도 이미 정의된 상수를 사용하는 편이 나을 것 같습니다,
return new Lotto(shuffledNumbers.subList(0, LottoConstants.LOTTO_SIZE.getValue())); | ||
} | ||
|
||
public static List<Lotto> generateLottos(List<List<Integer>> manualNumbers, int purchaseAmount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 메서드가 수동 로또 생성, 자동 로또 생성을 동시에 처리하고 있는 거 같아요. 각각 역할을 분리하면 가독성도 높아지고 한 가지 역할에 집중할 수 있을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀해주신대로, 수동 로또 생성과 자동 로또 생성을 분리해서 SRP를 준수하고
generateLotto에서는 수동로또생성 메서드와 자동로또생성 메서드를
호출하는 방식으로 바꾸면 좋을 것 같습니다! 감사합니다.
} | ||
|
||
private static int updateResults(Map<String, Integer> result, Lotto lotto, Set<Integer> winningSet, int bonusNumber) { | ||
int matchCount = (int) lotto.getNumbers().stream().filter(winningSet::contains).count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stream 사용 👍🏻 체이닝 방식을 쓰면 더 가독성 높아질 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스트림 체이닝에 대해서 공부해보겠습니다!
코드길이 단축과 중간변수를 선언하지 않아도 되어서 가독성과 유지보수에 이점이 있다고 하는군요,
} | ||
|
||
public static Optional<WinningRank> findByMatchCount(int matchCount, boolean hasBonus) { | ||
if (matchCount == 5 && hasBonus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이와 같이 하드 코딩된 조건문을 사용하는 것보다, Enum이 스스로 결정하고 검증할 수 있도록 하는 건 어떨까요?
예를 들면, isMatching
과 같은 메서드를 만들어서 자신과 주어진 값을 일치하는지 확인하는 방법으로요!
이 방법에 대한 준석님의 의견이 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum에서 스스로 상태를 결정해준다는 것에 대해서 생각해보지 못했는데,
그런 방법도 있군요!
규칙을 한 곳에서 관리해주기에도 유리할 것 같습니다 감사합니다.
while (true) { | ||
try { | ||
purchaseAmount = InputView.getPurchaseAmount(); | ||
LottoValidator.validatePurchaseAmount(purchaseAmount); | ||
break; | ||
} catch (IllegalArgumentException e) { | ||
ResultView.printInvalidAmountMessage(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재입력을 받는 접근은 좋아요 👍🏻
하지만 요구사항에 indent depth
가 1로 제한하고 있기 때문에, 재입력보다는 예외 처리를 하면 더 간결해질 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do while문 사용에 익숙치 않아서 위와 같은 방법으로 작성한 것 같습니다!
지윤님 말씀대로, 예외 발생시 반복입력을 요청하도록 하는 방법도 괜찮은 것 같습니다.
import java.util.stream.Collectors; | ||
|
||
public class LottoMachineController { | ||
public void run() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run() 메서드가 다양한 책임을 가지고 있어요.
흐름을 표현한 것은 좋지만, 메서드 분리가 되어있지 않으니 가독성이 떨어지는 것 같아요. 각 역할에 맞게 메서드를 분리하면 좋을 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀해주신대로, 런에서 모두 처리하는 것 보다 메서드를 분리해서 호출해서 사용하는편이 더 나은 것 같습니다!
src/main/java/view/InputView.java
Outdated
List<String> manualNumbers = new ArrayList<>(); | ||
for (int i = 0; i < count; i++) { | ||
System.out.printf("로또 번호 %d/%d 입력: ", i + 1, count); | ||
manualNumbers.add(scanner.nextLine().trim()); | ||
} | ||
return manualNumbers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InputView
에서 입력한 값을 저장하는 역할까지 맡는 것이 적절할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인풋뷰의 역할은 입력받기에 집중해야하는데, SRP를 준수하지 못한 것 같습니다.
해당 역할은 컨트롤러에서 처리하면 될 것 같습니다.
스터디 정보
❓ 질문
< 코드상 구조 >
LottoConstants (Config)
LottoValidator (Config)
WinningRank (Config)
LottoMachineController (Controller)
LottoMachine (Model)
Lotto (Model)
LottoResultChecker (Model)
InputView (View)
ResultView (View)
Application