Skip to content

Conversation

@sjiwon
Copy link
Collaborator

@sjiwon sjiwon commented Jun 25, 2023

Commit 단위는 현 미션은 클래스 단위로 적용했는데 다음 미션부터 Atomic하게 나눌 예정

@sjiwon sjiwon requested a review from SangBeom-Hahn June 25, 2023 10:11
@sjiwon sjiwon changed the title sjiwon - 숫자 야구 게임 숫자 야구 게임 [sjiwon] Jul 1, 2023
Comment on lines +48 to +50
public List<Integer> getBaseballs() {
return Collections.unmodifiableList(baseballs);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Collections.unmodifiableList는 Read-only라도 원본 컬렉션의 불변성을 보장하지 않는다고 합니다. CopyOf가 아닌 unmodifiableList를 사용하신 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unmodifiableList를 사용하는거는 원본 객체에 대해서 immutable을 보장하지는 않는데 구조상 Baseballs의 원본 객체를 외부에서 접근할 수 없고 외부에서 얻는 List<Integer> baseballs는 immutable이기 때문에 unmodifiableList를 써도 상관없다고 생각했습니다.

  • copyOf를 안쓴이유는 어차피 외부에서 얻는 baseball은 immutable이 보장되기 때문에 굳이 매번 복사할 필요가 없다고 생각

Comment on lines 20 to 25
while (baseballs.size() != BASEBALL_SIZE) {
int randomNumber = Randoms.pickNumberInRange(MIN_BASEBALL, MAX_BASEBALL);
if (!baseballs.contains(randomNumber)) {
baseballs.add(randomNumber);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

while 조건으로 size가 3을 초과하는 경우를 생각해서 less를 쓰는 게 좋지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not equal보다는 less가 더 적절하겠네요

Comment on lines +27 to +37
while (gameStatus.isGameNotTerminated()) {
// User - Baseball 입력
readUserBaseballInput();

// 게임 결과 확인
Result result = judgeGameByReferee();
OutputView.printGameResult(result);

// 게임 클리어 확인
checkGameClear(result);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://github.com/kgu-woowa/woowa-java-baseball/blob/ba99c7e7ad9b5457bf2937dd3b69bfc7066dbdb7/src/main/java/baseball/controller/GameController.java#L40-L43

위 코드를 보면 while문을 돌면서 readUserBaseballInput()에서 입력을 받을 때마다 User 객체를 생성하고

https://github.com/kgu-woowa/woowa-java-baseball/blob/ba99c7e7ad9b5457bf2937dd3b69bfc7066dbdb7/src/main/java/baseball/model/User.java#L8-L10

위 코드에서 User 객체를 만들 때마다 Baseballs 객체를 생성하게 되는데 이러면 사용자가 숫자를 입력 할 때마다 메모리를 먹게 될 것 같고

또 한 번의 게임에서 숫자 입력마다 사용자를 새로 생성하는 것은 요구사항에 안 좋게 보일 수 있을 거 같은데 어떻게 생각하시나요?

Copy link
Collaborator Author

@sjiwon sjiwon Jul 2, 2023

Choose a reason for hiding this comment

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

코드 구조상 게임을 클리어한 후 사용자가 재시작 [1] Command를 요청했을 경우 게임을 다시 시작하는데 여기서 다시 시작하는 부분은 요구사항 이해에 따라서 다르긴한데 저는 완전히 새로운 게임으로 판단하였고 그에 따라서 determineGameRestartOrEnd -> new Computer() / readUserBaseballInput -> new User(~~)로 초기화를 하는게 깔끔하다고 생각했습니다.

  • 내부 N개의 게임 Cycle을 전체적인 시작 ~ 종료의 한 게임이라고 본다면 computer & user상에 baseballs을 초기화하고 다시 갈아끼우는 로직을 넣는것도 괜찮아 보이네요

메모리 관련 부분은 사실 Computer나 User나 그렇게 큰 리소스를 잡아먹는다고 생각하지 않고 내부에서 관리하는 List또한 어차피 필드 자체는 3개로 제한되기 때문에 이 부분이 메모리에 큰 영향을 준다고 생각은 하지 않습니다

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.

3 participants