Skip to content

Conversation

@Mo-bile
Copy link

@Mo-bile Mo-bile commented Nov 27, 2025

안녕하세요?
리뷰 요청드립니다 👍

금번 보너스 번호 기능을 추가하면서 어디 object에 2,3등 간에 등수를 결정시킬지 고민을 오래한것 같습니다.

그 결과

  1. 로또 번호에 대한 추가 검증이므로 'rankDecideByBonusNumber 메서드를 추가
  2. Bonus 클래스를 새로 만들어 보너스 번호와 로또 번호의 한번 더 검증
  3. Rank 클래스에 2 혹은 3등인지 구분하는 메서드

이렇게 크게 구분하여 이번 미션을 진행한 것 같습니다.
단순하게 구현하면 indent 가 2이상 늘어나버리고 복잡한 형태가 만들어지고, 보기싫어지고 읽기 싫어지더라고요

처음에 요구사항을 보면 쉽다고 생각했는데 막상 해보니 녹록치 않은 과제였던 것 같습니다

좋은 과제 감사드립니다 💯

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단계 미션 진행하느라 수고했어요. 👍
적은 수의 객체 분리로 로또 미션 진행했는데요.

  • 규칙 3: 모든 원시값과 문자열을 포장한다.
  • 규칙 8: 일급 콜렉션을 쓴다.

위 두 개 원칙을 지키면서 객체 분리에 대한 리팩터링 도전해 보세요.
추가로 메서드 이름이 의도를 드러내지 못하는 경우가 많은데요.
메서드 이름은 가능하면 AI에게 피드백을 받아 개선해 보는 습관을 들여보면 좋겠습니다.

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.

피드백 반영하느라 수고 했어요. 👍
2단계에서 3단계로 오면서 당첨 번호에 보너스 번호가 추가되었는데요.
당첨 번호를 담당하는 객체를 추가해 보면 어떨까요?
이렇게 당첨 번호를 담당하는 객체를 추가하면서 Lotto의 책임과 역할을 당첨 번호를 담당하는 객체로 이동해 볼 것을 추천합니다.

모재영 added 5 commits November 29, 2025 16:53
2. 포함여부에 대한 구현 대신 컬렉션 API 활용하여 간편하게 변경
3. LottoNumber 객체가 생겨서 출력이 상이해진 부분 수정
4. 테스트 코드 금액표시에 3자리수 마다 _ 추가하여 가독성 향상
1. WinningLotto 신설해서 당첨값 관리 책임에 대한 객체 신설
2. Rank 와 Lotto 간에 순환 참조 개선 (순위 뽑은 뒤 다시 2,3등 뽑는구조 개선)
1. 등수를 최종 지정하는 역할을 Rank 에서 WinningLotto 로 이관
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.

이전 단계보다 확실히 코드가 많이 개선되었음을 느낄 수 있네요. 👍
코드 컨벤션도 잘 지키고 있네요.
다음 단계 넘어가기 전에 꼭 연습해 봤으면 하는 부분이 있어 피드백 남겨요.
LottoNumber 재사용 부분만 반영하고 다음 단계로 가시죠.

@@ -0,0 +1,18 @@
package lotto.domain.model;

public record LottoNumber(int value) {
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과 같은 곳에 인스턴스를 생성한 후 재사용하는 방법을 찾아본다.


import lotto.domain.Rank;

public record WinningLotto(LottoNumber bonusNumber, Lotto winNumbers) {
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
public record WinningLotto(LottoNumber bonusNumber, Lotto winNumbers) {
public record WinningLotto(Lotto winNumbers, LottoNumber bonusNumber) {

저 같으면 로또를 첫 번째 인자로 구현할 것 같음

}
}

public Rank rankDecide(Lotto lotto) {
Copy link
Contributor

Choose a reason for hiding this comment

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

WinningLotto로 이 메서드를 이동한 점 👍


private void increaseCount(Match match) {
this.matchMap.compute(match, (k, count) -> {
public void recordRank(Rank rank) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

this.winnerReturn = winnerReturn;
}

public static Rank valueOf(int matchCount, boolean bonusMatch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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.

캐시 적용 잘 했네요. 👍
단, 캐시 적용에 아쉬운 부분이 있어 피드백했으니 4단계 진행할 때 함께 반영해 보세요.
4단계는 최대한 컴파일 에러를 내지 않으면서 안정적으로 기능 추가하는 연습해 볼 것을 추천해요.


public record LottoNumber(int value) {

public LottoNumber(String value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

캐시 적용 👍
단 이와 같이 구현할 경우 캐시를 사용하지 않고 LottoNumber를 직접 생성 가능하다.
LottoNumber를 외부에서 직접 생성하지 못하도록 private으로 구현하고 캐시 효과를 내도록 리팩터링해본다.

힌트: 정적 팩터리 메서드

@javajigi javajigi merged commit f730021 into next-step:mo-bile Nov 30, 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.

2 participants