Skip to content

Conversation

@023-dev
Copy link
Contributor

@023-dev 023-dev commented Nov 19, 2024

숫자 야구 미션

고민했던 부분

  • 상수 클래스에 대한 생각
  • 원시타입의 자료형 커스텀 래핑클래스에 대한 생각
  • 일급 컬렉션을 래핑한 클래스에 대한 생각
  • 단순히 데이터를 담는 것이 아니라 연산 책임을 가지게 함으로써, 컬렉션의 불변성과 안전성을 유지
  • 입력 프롬프트에 대한 생각
  • 에러 클래스에 대한 생각
  • 메소드 10줄에 대한 생각
  • else 제한에 대한 생각

패키지 구조

classDiagram
    direction TB

    class baseball {
        Application
    }

    baseball "1" --> "1" common
    baseball "1" --> "1" config
    baseball "1" --> "1" controller
    baseball "1" --> "1" model
    baseball "1" --> "1" view

    class common {
        <<package>>
    }
    common --> constant
    class constant {
        Constants
    }

    class config {
        <<package>>
        GameConfig
    }

    class controller {
        <<package>>
        GameController
    }

    class model {
        <<package>>
    }
    model --> domain
    class domain {
        ComputerNumbers
        GameMenu
        PlayerNumbers
        Result
    }

    class view {
        <<package>>
        InputView
        OutputView
    }
Loading

클래스 다이어그램

classDiagram
direction BT
class Application {
  + main(String[]) void
  + Application() 
}
class ComputerNumbers {
  - createRandomNumbers() List~Integer~
  + compare(PlayerNumbers) Result
  + ComputerNumbers() 
}
class Constants {
  + Constants() 
}
class GameConfig {
  + GameConfig() 
   GameController gameComputer
}
class GameController {
  - result(ComputerNumbers, PlayerNumbers) boolean
  - input() PlayerNumbers
  - init() ComputerNumbers
  - restart() boolean
  - play() void
  - finish() void
  + start() void
  + GameController(InputView, OutputView) 
}
class GameMenu {
<<enumeration>>
  + valueOf(String) GameMenu
  + from(String) boolean
  + values() GameMenu[]
  - GameMenu(String, boolean) 
   boolean countinue
  - boolean countinue
}
class InputView {
  + askRestart() String
  + InputView() 
   String number
}
class OutputView {
  + printRestartPrompt() void
  + printNumberPrompt() void
  + printFinishMessage() void
  + printResultMessage(String) void
  + printStartMessage() void
  + printErrorMessage(String) void
  + OutputView() 
}
class PlayerNumbers {
  - parse(String) List~Integer~
  - parseNumber(String) int
  - validateNumber(int) int
  - validateNumbers(List~Integer~) void
  + PlayerNumbers(String) 
   List~Integer~ playerNumbers
  - List~Integer~ playerNumbers
}
class Result {
  + toString() String
  + Result(int, int) 
   boolean correct
}

GameConfig "1" *--> "gameController 1" GameController 
GameConfig "1" *--> "inputView 1" InputView 
GameConfig "1" *--> "outputView 1" OutputView 
GameController "1" *--> "inputView 1" InputView 
GameController "1" *--> "outputView 1" OutputView 

Loading

플로우 차트

graph TD
    A[게임 시작] --> B[시작 메시지 출력]
    B --> C{게임을 계속 진행할까요?}
    C -->|예| D[컴퓨터 숫자 초기화]
    D --> E{게임 종료 여부 확인}
    E -->|아니오| F[플레이어 숫자 입력]
    F --> G[결과 비교]
    G --> H[결과 메시지 출력]
    H --> E
    E -->|예| I[종료 메시지 출력]
    I --> J{다시 시작할까요?}
    J -->|예| C
    J -->|아니오| K[게임 종료]

Loading

Copy link

@tiemo0708 tiemo0708 left a comment

Choose a reason for hiding this comment

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

스터디 고생하셨습니다!

Comment on lines +35 to +44
for (int i = 0; i < NUMBERS_SIZE; i++) {
boolean isStrike = computerNumbers.get(i).equals(playerNumbers.get(i));
boolean isBall = !isStrike && computerNumbers.contains(playerNumbers.get(i));
if (isStrike) {
strikes++;
}
if (isBall) {
balls++;
}
}

Choose a reason for hiding this comment

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

해당 클래스에 스트라이크, 볼 판정 로직이 있어도 될지 궁금합니다

Comment on lines +6 to +7
RESTART("1", true),
QUIT("2", false);

Choose a reason for hiding this comment

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

재시작을 이넘으로 처리하셨네요 좋은방법 같아 보입니다

validateNumber(number);
return number;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("입력값은 숫자여야 합니다.");

Choose a reason for hiding this comment

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

예외처리도 상수화 하시면 좋을것 같습니다


public class InputView {

public String getNumber() {

Choose a reason for hiding this comment

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

메서드이름에 get이 들어가는걸 지양해야할것 같습니다

Comment on lines +13 to +23
private List<Integer> parse(String input) {
List<String> items = List.of(input.split(""));
List<Integer> numbers = new ArrayList<>();
for (String item : items) {
int number = parseNumber(item);
numbers.add(number);
}
validateNumbers(numbers);
return numbers;
}

Choose a reason for hiding this comment

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

파싱 부분은 따로 클래스를 만들어서 빼는게 어떨까요?

Copy link

@jiffyin7 jiffyin7 left a comment

Choose a reason for hiding this comment

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

스터디 때 뵙겠습니다.

Comment on lines +33 to +38
boolean isFinish = false;
ComputerNumbers computerNumbers = init();
while (!isFinish) {
PlayerNumbers playerNumbers = input();
isFinish = result(computerNumbers, playerNumbers);
}

Choose a reason for hiding this comment

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

do while로 처리하면 더 좋을것 같습니다.

private final List<Integer> computerNumbers;

public ComputerNumbers() {
this.computerNumbers = createRandomNumbers();

Choose a reason for hiding this comment

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

생성자에서 온전히 생성만을 담당하기 위해
생성로직을 분리하는것은 어떨까요?

}

public boolean isCorrect() {
return strikes == 3;

Choose a reason for hiding this comment

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

NUMBER_SIZE 상수를 써도 좋을것 같네요.

Copy link

@Dompoo Dompoo left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 스터디에서 보아요~!!

Comment on lines +8 to +11
public final static String WHITE_SPACE = " ";
public final static String STRIKE = "%d스트라이크";
public final static String BALL = "%d볼";
public final static String NOTHING = "낫싱";
Copy link

Choose a reason for hiding this comment

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

이 상수들은 위 상수들과는 조금 다르게 출력에 초점을 맞추고 있는 상수들이에요. 상수도 분리해서 관리하면 어떨까요?

Comment on lines +27 to +28
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage());
Copy link

Choose a reason for hiding this comment

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

어차피 IllegalArgumentException으로 받아서 똑같은 메시지로 다시 던질거면 여기서 try-catch를 왜 사용하신지 궁금해요!

Comment on lines +24 to +25
play();
isContinue = restart();
Copy link

Choose a reason for hiding this comment

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

메서드가 아주 보기 좋게 잘려있으니 이 둘을 서비스나 다른 컨트롤러로 분리하기 아주 좋아보입니다. ㅎㅎ.... (츄릅)
어떻게 생각하세요?

import java.util.ArrayList;
import java.util.List;

public class PlayerNumbers {
Copy link

Choose a reason for hiding this comment

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

PlayerNumber와 ComputerNumeber가 비슷한 기능을 수행하는 부분이 있어서, 추상클래스로 묶으면 검증등의 로직을 빼볼 수 있을 것 같아요!


import static camp.nextstep.edu.missionutils.Console.readLine;

public class InputView {
Copy link

Choose a reason for hiding this comment

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

InputView에서 좀 더 적극적으로 List나 boolean을 제공하지 않고, String만 제공하는지 궁금합니다! 너무 역할이 없는 것 같아요.

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.

4 participants