Skip to content

Conversation

@GunBros
Copy link

@GunBros GunBros commented Dec 8, 2025

안녕하세요 재성님. 3단계 - 로또(2등) PR입니다. 항상 리뷰 감사합니다!

Copy link
Contributor

@javajigi javajigi left a comment

Choose a reason for hiding this comment

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

3단계 구현하느라 수고했어요. 👍
단, 주 생성자/부 생성자 사용에 아직은 익숙하지 않은 느낌이 드네요.
피드백에 남겼는데 주 생성자/부 생성자 관련해 추가 학습하고 적용하고 습관을 들여볼 것을 추천합니다.
추가로 불변 객체로 구현할 경우 발생하는 성능 이슈에 대한 해결책을 찾아봤으면 좋겠어서 피드백 남겼어요.

import lotto.domain.LottoResult;


public class WinningLotto {
Copy link
Contributor

Choose a reason for hiding this comment

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

controller가 아니라 domain 객체가 아닐까?


for (LottoNumbers lottoNumbers : lottoNumbers) {
LottoRank rank = lottoNumbers.getMatchedRank(winningNumbers);
LottoRank rank = lottoNumbers.getMatchedRank(winningNumbers, bonusNumber);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LottoRank rank = lottoNumbers.getMatchedRank(winningNumbers, bonusNumber);
LottoRank rank = winningLotto.getMatchedRank(lottoNumbers);

WinningLotto 객체를 도메인 객체로 생각하고 위와 같이 WinningLotto에 등수를 구하는 책임을 부여하는 것은 어떨까?

import java.util.Objects;

public class LottoNumber {
private final int number;
Copy link
Contributor

Choose a reason for hiding this comment

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

상황

  • 웹 백엔드 서버로 1만명의 사용자가 동시에 당첨 여부를 확인할 수 있어야 한다.
  • 1명의 사용자는 평균 5장의 로또를 구매한 상태이다.

위 요구사항을 서버에서 생성되는 LottoNumber의 인스턴스의 갯수는?
1 * 5장 * 6개 숫자/1장 * 1만명 = 30만개이다.

동시에 생성되는 인스턴스 갯수가 너무 많다.
인스턴스 갯수를 줄일 수 있는 방법은?
로또 숫자 값을 LottoNumber 객체로 래핑하는 경우 매번 인스턴스가 생성되기 때문에 인스턴스의 갯수가 너무 많아져 성능이 떨어질 수 있다.
LottoNumber 인스턴스를 생성한 후 재사용할 수 있도록 구현한다.

힌트 : Map과 같은 곳에 인스턴스를 생성한 후 재사용하는 방법을 찾아본다.****

this.numbers = toLottoNumber(numbers);
}

public LottoNumbers(int... numbers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

import java.util.Objects;
import java.util.stream.Collectors;

public class LottoNumbers {
Copy link
Contributor

Choose a reason for hiding this comment

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

주 생성자와 부 생성자에 대해 추가 학습하고 적용해 보면 습관을 들일 것을 추천

"4차 라이브 강의 - 테스트 가능한 구조, 인터페이스 분리" 강의의 "28분 13초: 다수의 생성자의 필요성, 주 생성자 & 부 생성자" 영상을 통해 추가 학습해 보고 리팩터링한다.

this(convertToList(numbers));
}

private static List<LottoNumber> toLottoNumber(List<Integer> numbers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

로또 한 장과 당첨 번호가 유효하려면 다음 조건을 만족해야 한다.

  • 로또 한 장은 6개의 번호여야 한다.
  • 6개의 각 숫자는 1에서 45 사이의 값이어야 한다.
  • 6개의 값은 중복된 값이 있으면 안된다.
  • 당첨 번호의 경우는 보너스 번호가 1에서 45 사이의 값이어야 하여, 보너스 번호는 당첨 번호 6개의 값이 아니어야 한다.

위와 같은 복잡한 유효성 체크를 어떻게 해결하면 좋을까?

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