-
Notifications
You must be signed in to change notification settings - Fork 0
숫자 야구 게임 [sjiwon] #1
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: main
Are you sure you want to change the base?
Conversation
| public List<Integer> getBaseballs() { | ||
| return Collections.unmodifiableList(baseballs); | ||
| } |
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.
Collections.unmodifiableList는 Read-only라도 원본 컬렉션의 불변성을 보장하지 않는다고 합니다. CopyOf가 아닌 unmodifiableList를 사용하신 이유가 있을까요?
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.
unmodifiableList를 사용하는거는 원본 객체에 대해서 immutable을 보장하지는 않는데 구조상 Baseballs의 원본 객체를 외부에서 접근할 수 없고 외부에서 얻는 List<Integer> baseballs는 immutable이기 때문에 unmodifiableList를 써도 상관없다고 생각했습니다.
- copyOf를 안쓴이유는 어차피 외부에서 얻는 baseball은 immutable이 보장되기 때문에 굳이 매번 복사할 필요가 없다고 생각
| while (baseballs.size() != BASEBALL_SIZE) { | ||
| int randomNumber = Randoms.pickNumberInRange(MIN_BASEBALL, MAX_BASEBALL); | ||
| if (!baseballs.contains(randomNumber)) { | ||
| baseballs.add(randomNumber); | ||
| } | ||
| } |
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.
while 조건으로 size가 3을 초과하는 경우를 생각해서 less를 쓰는 게 좋지 않을까요?
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.
not equal보다는 less가 더 적절하겠네요
| while (gameStatus.isGameNotTerminated()) { | ||
| // User - Baseball 입력 | ||
| readUserBaseballInput(); | ||
|
|
||
| // 게임 결과 확인 | ||
| Result result = judgeGameByReferee(); | ||
| OutputView.printGameResult(result); | ||
|
|
||
| // 게임 클리어 확인 | ||
| checkGameClear(result); | ||
| } |
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.
위 코드를 보면 while문을 돌면서 readUserBaseballInput()에서 입력을 받을 때마다 User 객체를 생성하고
위 코드에서 User 객체를 만들 때마다 Baseballs 객체를 생성하게 되는데 이러면 사용자가 숫자를 입력 할 때마다 메모리를 먹게 될 것 같고
또 한 번의 게임에서 숫자 입력마다 사용자를 새로 생성하는 것은 요구사항에 안 좋게 보일 수 있을 거 같은데 어떻게 생각하시나요?
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.
코드 구조상 게임을 클리어한 후 사용자가 재시작 [1] Command를 요청했을 경우 게임을 다시 시작하는데 여기서 다시 시작하는 부분은 요구사항 이해에 따라서 다르긴한데 저는 완전히 새로운 게임으로 판단하였고 그에 따라서 determineGameRestartOrEnd -> new Computer() / readUserBaseballInput -> new User(~~)로 초기화를 하는게 깔끔하다고 생각했습니다.
- 내부 N개의 게임 Cycle을 전체적인 시작 ~ 종료의 한 게임이라고 본다면 computer & user상에 baseballs을 초기화하고 다시 갈아끼우는 로직을 넣는것도 괜찮아 보이네요
메모리 관련 부분은 사실 Computer나 User나 그렇게 큰 리소스를 잡아먹는다고 생각하지 않고 내부에서 관리하는 List또한 어차피 필드 자체는 3개로 제한되기 때문에 이 부분이 메모리에 큰 영향을 준다고 생각은 하지 않습니다
- baseball 입력 -> space 확인 -> 정수 확인 - restart command -> space 확인 -> 정수 확인
Uh oh!
There was an error while loading. Please reload this page.