Conversation
- 1~ 9까지의 숫자 체크 - 서로 다른 숫자 체크
- 위치, 숫자 모두 맞춘경우 -> 스트라이크
- 위치는 틀리고 숫자만 맞춘 경우 -> 볼
- 위치, 숫자 모두 틀린 경우 -> 낫싱
|
|
||
| public abstract class GameInput { | ||
|
|
||
| public static final String REQUEST_RE_INPUT_MESSAGE = "다시 입력해주세요."; | ||
|
|
||
| public InputNumbers getUserInputNumbers() { | ||
|
|
||
| String inputStr = inputStr = input(); | ||
| List<Integer> inputs = convertToIntegerList(inputStr); | ||
|
|
||
| InputNumbers inputNumbers = null; | ||
| try { | ||
| inputNumbers = new InputNumbers(inputs); | ||
|
|
||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(REQUEST_RE_INPUT_MESSAGE); | ||
| getUserInputNumbers(); | ||
| } | ||
|
|
||
| return inputNumbers; | ||
| } | ||
|
|
||
| public ConfirmCommand inputConfirmCommand() { | ||
| ConfirmCommand confirmCommand = null; | ||
|
|
||
| try { | ||
| confirmCommand = ConfirmCommand.findConfirmCommand(input()); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(REQUEST_RE_INPUT_MESSAGE); | ||
| inputConfirmCommand(); | ||
| } | ||
|
|
||
| return confirmCommand; | ||
| } | ||
|
|
||
| private List<Integer> convertToIntegerList(String inputStr) { | ||
| return Arrays.stream(inputStr.split("")) | ||
| .map(Integer::parseInt) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| protected abstract String input(); | ||
|
|
||
| } |
There was a problem hiding this comment.
입력 UI를 구현할 때, TemplateMethodPattern을 적용해봤습니다.
| ConfirmCommand confirmCommand = input.inputConfirmCommand(); | ||
| if (confirmCommand.isExit()) { | ||
| return; | ||
| } | ||
|
|
||
| start(); // 재귀사용 | ||
| return; | ||
| } |
There was a problem hiding this comment.
재원님이 말씀해주셨던 피드백중에 "재귀식"에 대한 내용이 기억나서
이번에 반복되는 처리에 대해서 재귀식으로 구성해봤습니다.
| public class RandomNumberGenerator { | ||
|
|
||
| private final int MAX = 9; | ||
|
|
||
| private final int MIN = 1; | ||
|
|
||
| private final Random random; | ||
|
|
||
| public RandomNumberGenerator() { | ||
| this.random = new Random(); | ||
| } | ||
|
|
||
| public int generate() { | ||
| return random.nextInt((MAX - MIN) + 1) + MIN; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
RandomNumber에 대한 생성의 책임은 RandomNumberGenerator라는 객체에게 부여했습니다.
| this.number = number; | ||
| } | ||
|
|
||
| public int getPosition() { |
There was a problem hiding this comment.
getter가 특별한 이유 없이 public으로 노출되고 있어요 🤔
| private final List<Ball> balls; | ||
|
|
||
| public Balls(InputNumbers inputNumbers) { | ||
| balls = new ArrayList<>(); |
There was a problem hiding this comment.
생성자에서는 단순한 값의 초기화만 이루어져야 좋다고 생각해요.
생성자에서 단순히 List을 받고, static 팩토리 메서드로 다양한 생성 방법을 노출하면 어떨까요? 🤔
| numbers.forEach(this::addInputNumber); | ||
| } | ||
|
|
||
| // TODO : getter가 있어도 될까? |
There was a problem hiding this comment.
getter로 노출 하는건 굉장히 좋지 못하다고 생각해요!
| this.ballCount = ballCount; | ||
| } | ||
|
|
||
| public int getStrikeCount() { |
There was a problem hiding this comment.
strikeCount를 알려주지 않고 Score에게 strikeCount값을 물어보면 어떨까요?
| } | ||
|
|
||
| public String makeResultMessage() { | ||
| StringBuilder stringBuilder = new StringBuilder(); |
There was a problem hiding this comment.
ResultMessage를 만들어 주는건 도메인의 역할이 아니라고 생각해요
| @@ -0,0 +1,19 @@ | |||
| import java.util.Random; | |||
|
|
|||
| public class RandomNumberGenerator { | |||
|
고생 하셨습니다. |
재성님의 플이영상을 한번 봤더니
코드가 비슷해지는군요.. ㅜㅜ
자꾸 그게 생각이나다보니... ㅜㅜ
다음부터는 풀이강의는 최대한 늦게 봐야겠어요 ㅜㅜ
부족한 소스지만 시간 되실 때 리뷰 한번만 부탁드립니다!
제가 생각하기에 "좀 특이한 것 같다~" 라는 사항은 코멘트에 달아놨습니다.
감사합니다.