-
Notifications
You must be signed in to change notification settings - Fork 1.1k
4단계 - 로또(수동) #4246
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
4단계 - 로또(수동) #4246
Conversation
javajigi
left a comment
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.
4단계 수동 로또 미션 진행 👍
확실히 4단계는 큰 변화 없이 요구사항 추가할 수 있었네요.
추가로 인터페이스 연습해 봤으면 하는 바람으로 피드백 하나 남겼으니 한번 적용해 보세요.
| return Optional.ofNullable(cache.get(value)) | ||
| .orElseThrow(() -> new IllegalArgumentException("로또 번호는 1부터 45 사이의 숫자여야 합니다.")); |
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.
👍
| return new Lotto(list.subList(0, Lotto.LOTTO_COUNT)); | ||
| } | ||
|
|
||
| public static Lottos generate(BigDecimal amount, Lottos manualLotto) { |
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.
3단계에서 4단계로 요구사항이 변경될 때 로또를 생성하는 부분의 요구사항만 변경됐다.
로또를 생성하는 부분을 다음과 같은 구조의 인터페이스로 분리해 보는 연습을 해보면 어떨까?
이와 같이 인터페이스로 구현했을 때의 잇점에 대해 고민해 보는 시간을 가져본다.
Lottos는 사용자가 구매한 n장의 로또를 추상화한 객체임
public interface LottosGenerator {
Lottos generate();
}|
|
||
| int bonusNumber = scanner.nextInt(); | ||
| return LottoNumber.valueOf(bonusNumber); | ||
| private static <T> T inputWithRetry(String message, String errorMessage, Supplier<T> input) { |
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.
👍
- LottoGenerator 인터페이스로 로또 생성 전략 추상화
javajigi
left a comment
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.
MixedLottosGenerator을 통해 통합한 것이 인상적임 💯
MixedLottosGenerator 구현에 대한 다른 접근 방식도 있어 바로 머지하려다 마지막으로 피드백 한번 남겨 봅니다.
| import lotto.domain.LottoPurchase; | ||
| import lotto.domain.Lottos; | ||
|
|
||
| public class MixedLottosGenerator implements LottoGenerator { |
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.
MixedLottosGenerator을 추가한 것 👍
보통 디자인 패턴에서 컴포지트 패턴으로 알려져 있음.
아래와 같이 구현해 보는 것은 어떨까?
public class LottosBundleGenerator implements LottosGenerator {
private final List<LottosGenerator> lottosGenerators;
public LottosBundleGenerator(Money money, List<String> manualLottoText) {
this(toLottosGenerators(money, manualLottoText));
}
private static List<LottosGenerator> toLottosGenerators(Money money, List<String> manualLottoText) {
// manualLottoText 활용해 ManualLottosGenerator 생성
// money에서 수동으로 구매한 로또 수 만큼 차감한 후 AutoLottosGenerator 생성
}
public LottosBundleGenerator(List<LottosGenerator> lottosGenerators) {
this.lottosGenerators = lottosGenerators;
}
@Override
public Lottos generate() {
// List<LottosGenerator> 반복문 돌며 로또 생성
return 두 로또를 합쳐서 반환;
}
}- MixedLottosGenerator를 LottosBundleGenerator로 변경하여 컴포지트 패턴으로 수정했습니다.
javajigi
left a comment
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.
지금까지 로또 미션 진행하느라 수고했어요. 👍
앞으로 개발자로 성장하는데 도움이 되었기를 바랍니다.
📌 Summary
🤔 고민한 점 및 질문
InputView에사용자가 잘못된 값을 입력했을 때 java exception으로 에러 처리를 한다.요구사항을 적용하기 위해 중복된 코드를 따로 메서드로 분리했는데요. 이 접근이 올바른 접근인지 고민이 되었습니다.