Skip to content
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

java-racingcar(songpang) #3

Open
wants to merge 63 commits into
base: songpang
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0a5d963
docs: 기능 구현 목록 및 클래스 정리
chae-heechan Mar 4, 2021
216cb6d
test: 입력 및 유효성 검사 클래스 테스트 케이스 작성
chae-heechan Mar 4, 2021
ae04e19
feat: Receiver 클래스 구현
chae-heechan Mar 4, 2021
a6e8c0f
feat: Validator 인터페이스 생성
chae-heechan Mar 4, 2021
804fe2d
docs: 클래스 분류 재정리
chae-heechan Mar 4, 2021
a02977d
feat: Message인터페이스 생성
chae-heechan Mar 4, 2021
3ac806d
test: validator클래스 구조 변경에 따른 테스트 변경
chae-heechan Mar 9, 2021
a973407
feat: 출력 메세지 인터페이스 작성
chae-heechan Mar 9, 2021
78bb06d
refactor: 메세지 호출 메서드 삭제, 입력 예외 추가
chae-heechan Mar 9, 2021
bb9c87b
feat: 프린터 클래스 구현
chae-heechan Mar 9, 2021
07f6628
feat: 게임 시작 기능 추가
chae-heechan Mar 9, 2021
cdfc826
docs: 클래스 및 메서드 분류 재정리
chae-heechan Mar 9, 2021
0ff13cc
feat: Car클래스 구현
chae-heechan Mar 9, 2021
6519379
feat: Message클래스 구현
chae-heechan Mar 9, 2021
7aaac17
feat: Validator클래스 구현
chae-heechan Mar 9, 2021
b115436
refactor: receiveLine 메서드 삭제
chae-heechan Mar 9, 2021
8d840f7
feat: 게임 실행 부분 구현
chae-heechan Mar 9, 2021
74d8054
feat: 난수 생성 기능 구현
chae-heechan Mar 9, 2021
02b5186
style: overSizeCharacters 메서드 이름 변경
chae-heechan Mar 10, 2021
6954307
test: Paramiterizedtest로 변경
chae-heechan Mar 10, 2021
305ea0d
feat: 게임 내 출력 메서드 추가
chae-heechan Mar 10, 2021
fc3b773
test: Receiver 테스트 케이스 작성
chae-heechan Mar 10, 2021
e0fe4fa
docs: Paramiterized 테스트 사용하기 위해 testCompile 부분 추가
chae-heechan Mar 10, 2021
2d34588
style: overSizeCharacters 메서드 이름 변경
chae-heechan Mar 10, 2021
e1c98f3
style: 불필요한 라인 제거
chae-heechan Mar 10, 2021
38feeaa
test: Car 테스트 케이스 작성
chae-heechan Mar 10, 2021
c47f82f
test: GamePlayer 테스트 케이스 작성
chae-heechan Mar 10, 2021
2c62d0c
test: Generator 테스트 케이스 작성
chae-heechan Mar 10, 2021
838a38b
test: Message 테스트 케이스 작성
chae-heechan Mar 10, 2021
1a10b46
test: Printer 테스트 케이스 작성
chae-heechan Mar 10, 2021
d9fbd3a
style: overSizeCharacters 메서드 이름 변경
chae-heechan Mar 10, 2021
932e5fe
feat: 게임 내 출력 메서드 추가
chae-heechan Mar 10, 2021
ed3d8ac
test: Receiver 테스트 케이스 작성
chae-heechan Mar 10, 2021
e0b9f8d
feat: 게임 내 출력 메서드 추가
chae-heechan Mar 10, 2021
0b4dd36
refactor: 출력 부분 printer 객체에서 처리하도록 변경
chae-heechan Mar 10, 2021
7bb1ace
docs: empty 파일 삭제
chae-heechan Mar 10, 2021
c7d7fd1
refactor: 불필요한 public 제거
songpang Mar 20, 2021
66dd3b6
refactor: 메소드 및 변수 네이밍 수정
songpang Mar 20, 2021
a595c43
refactor: 위험한 접근 제어자 수정 및 불필요한 코드 제거
songpang Mar 20, 2021
0852319
refactor: 위와 같음
songpang Mar 20, 2021
422c3da
refactor: assertThat actual과 expected의 오용 수정
songpang Mar 20, 2021
8d80c12
refactor: 절차지향적인 코드 수정
songpang Mar 21, 2021
645be80
refactor: 이번 미션에서 불필요한 생성자 제거
songpang Mar 21, 2021
302139e
refactor: 불필요한 코드제거 및 획일성을 위한 상수 설정
songpang Mar 21, 2021
93dde0d
refactor: Printer클래스의 역할 제한 및 관련 메소드 이동
songpang Mar 21, 2021
bfb6277
refactor: Car 클래스에 maxNumber를 확인하는 역할 부여
songpang Mar 21, 2021
b87577f
refactor: MessageInterface 삭제 및 Message클래스 내부 Hashmap에서 enum으로 변경
songpang Mar 25, 2021
9a31667
refactor: 이전 커밋의 변경사항 Validator Class에 적용
songpang Mar 25, 2021
51d46b3
refactor: GamePlayer Class 위의 커밋 내용 적용
songpang Mar 25, 2021
5d7064e
refactor: Printer Class의 Progress bar 만드는 메소드 Car Class로 위임
songpang Mar 25, 2021
b3444f0
refactor: 사용하지 사용하지 않거나 불필요한 interface 삭제
songpang Mar 25, 2021
978faee
refactor: Winner Class 생성, Gameplayer Class 역할 분리
songpang Mar 25, 2021
eb18b53
refactor: Car Class에 자신의 position을 Progress bar로 리턴하는 역할 부여
songpang Mar 26, 2021
021f98d
refactor: README 수정
songpang Mar 26, 2021
c296369
refactor: 컨벤션 수정 및 구현체를 인터페이스로 변경
songpang Mar 28, 2021
e577df7
refactor: 메소드 역할 분리
songpang Mar 28, 2021
560f251
refactor: 제한자 및 컨벤션 수정
songpang Mar 28, 2021
8f84168
Update src/main/java/domain/Validator.java
songpang Mar 28, 2021
0428c22
Merge branch 'songpang' of https://github.com/songpang/java-racingcar…
songpang Mar 28, 2021
ed92c1f
Update src/main/java/domain/Winner.java
songpang Mar 28, 2021
83eaf8c
refactor: 접근 제한자 설정 및 변수명 변경
songpang Mar 28, 2021
54109bd
refactor: 실패 케이스 삭제
songpang Mar 28, 2021
506b630
Merge branch 'songpang' of https://github.com/songpang/java-racingcar…
songpang Mar 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# 미션 - 자동차 경주 게임

## 📋 기능 구현 목록
- 사용자 입력 요구문 출력
- 사용자 입력
- 예외 처리
- 플레이어 생성

- 경주 게임 실행
- 무작위 수 생성
- 4이상 인지 비교
- 1초 간격두고 라운드 결과 출력

- 우승자 판별
- 우승자 출력

## 🚬 클래스와 메서드?
- Application
- Receiver
- receiveName
- receiveNumber
- Printer
- printMessage
- GamePlayer
- run
- judgeToMove
- makeArrayAfterGettingName
- makeCountAfterGettingNumber
- launchAllRound
- checkWhoIsWinner
- Generator
- generateRandomNumber
- Car
- getPosition
- getName
- moveForward
- Validate
- validateName(s)
- inputNothing(s)
- inputCommaInARow(s)
- inputCharactersOtherThanName(s)
- startWithComma(s)
- endWithComma(s)
- over5Characters(s)
- inputSameName(s))
- validateNumber(s)
- Message


## 🚀 기능 요구사항

- 주어진 횟수 동안 n대의 자동차는 전진 또는 멈출 수 있다.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {

dependencies {
testCompile("org.assertj:assertj-core:3.14.0")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testCompile('org.junit.jupiter:junit-jupiter:5.6.0')
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import domain.GamePlayer;

public class Application {
public static void main(String[] args){
GamePlayer gamePlayer = new GamePlayer();
gamePlayer.run();
}
}
20 changes: 19 additions & 1 deletion src/main/java/domain/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,23 @@ public Car(String name) {
this.name = name;
}

// 추가 기능 구현
public int getPosition() {
return this.position;
}

public String getName() {
return this.name;
}

public void moveForward() {
this.position++;
}

public boolean isMaxNumber(int maxNumber) {
return this.position == maxNumber;
}

public boolean isOverMaxNumber(int maxNumber) {
return this.position > maxNumber;
}
}
98 changes: 98 additions & 0 deletions src/main/java/domain/GamePlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package domain;

import io.Printer;
import io.Receiver;

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

public class GamePlayer {
Copy link
Member

Choose a reason for hiding this comment

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

run을 제외한 모든 메서드들이 외부에서 호출될 필요가 없어보입니다.
public 접근 제어자로 설정하는 것이 괜찮을까요?

Copy link
Member

Choose a reason for hiding this comment

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

GamePlayer가 생각보다 많은 책임을 갖고 있는것 같아요.
차들을 생성해 내기도하고, 전진 가능한지를 판단하기도하고, 우승자를 찾기도하고 UI에 관련된 임무를 수행하기도 하네요!

클래스를 좀 더 분리해보는건 어떨까요? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

대부분의 메소드의 접근 제한자가 default인데 의도하신 건가요?

[Java] 접근 제한자

Copy link
Member Author

Choose a reason for hiding this comment

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

처음에 public으로 설정했다가 동민님이 외부에서 사용하지 않는데 굳이 public을 사용한 이유가 있냐고 피드백을 주셔서 이에 대해 고민해 본 이후 default로 변경했습니다!

Copy link
Member

Choose a reason for hiding this comment

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

아마 클래스 내부에서만 사용되는 메소드를 public으로 설정해서 그런 피드백을 주지 않았나 생각이 되네요 🙂

클래스 내부에서만 사용되는 메소드는 private, 외부에서 메세지를 전달받는 메소드는 public으로 설정하는 것이 좋을 것 같아요.

private static final int WINNER_CONDITION = 4;

private final Printer printer;
private final Receiver receiver;
private final Generator generator;

public GamePlayer() {
this.printer = new Printer();
this.receiver = new Receiver();
this.generator = new Generator();
}

void judgeAndMove(Car car, int randomNumber) {
Copy link
Member

Choose a reason for hiding this comment

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

judgeAndMove 라는것 자체로 메소드가 두가지 일을 하고 있다고 생각할 수 있지 않을까요?
메소드는 한가지 일만 할 수 있도록 메소드를 분리해봅시다 🙂

if (randomNumber >= WINNER_CONDITION)
car.moveForward();
Copy link
Member

Choose a reason for hiding this comment

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

핵데이 컨벤션 8.3 참고해주세요!

Suggested change
if (randomNumber >= WINNER_CONDITION)
car.moveForward();
if (randomNumber >= WINNER_CONDITION) {
car.moveForward();
}

Copy link
Member

Choose a reason for hiding this comment

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

컨벤션을 확인해주세요 🙂

}

Car[] makeArrayAfterGettingName() {
printer.printGeneralMessage("INPUT_NAMEOFCAR");
String[] listOfName = receiver.receiveName();

Car[] cars = new Car[listOfName.length];
for (int i = 0; i < listOfName.length; i++)
cars[i] = new Car(listOfName[i]);

return cars;
}

int makeCountAfterGettingNumber() {
printer.printGeneralMessage("INPUT_COUNT");
return receiver.receiveNumber();
}

void launchAllRound(Car[] cars, int countRound) {
for (int i = 0; i < countRound; i++) {
for (Car car : cars) {
judgeAndMove(car, generator.generateRandomNumber());
printer.printProgressWithSymbol(car.getName(), car.getPosition());
}
printer.printGeneralMessage("DEFAULT_SPACE");
}
}

List<Car> checkWhoIsWinner(Car[] cars) {
List<Car> winner = new ArrayList<>();
int maxNumber = 0;

for (Car car : cars) {
if(car.isMaxNumber(maxNumber)){
winner.add(car);
}
if (car.isOverMaxNumber(maxNumber)) {
maxNumber = initWinner(winner, car);
}
}

return winner;
}

private int initWinner(List<Car> winner, Car car) {
int maxNumber = car.getPosition();
winner.clear();
winner.add(car);

return maxNumber;
}

public String makeWinnerToString(List<Car> cars) {
String winner = cars.get(0).getName();

if(cars.size() > 1) {
for(int i = 1;i<cars.size();i++) {
winner += ", " + cars.get(i).getName();
}
}

return winner;
}
public void run() {
Car[] cars = makeArrayAfterGettingName();
int countRound = makeCountAfterGettingNumber();

printer.printGeneralMessage("OPERATION_RESULT");
launchAllRound(cars, countRound);

List<Car> winner = checkWhoIsWinner(cars);
printer.printWinner(makeWinnerToString(winner));
}
}
8 changes: 8 additions & 0 deletions src/main/java/domain/Generator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package domain;

public class Generator {
private final int MAX_LIMIT_NUMBER = 10; //default value
public int generateRandomNumber() {
return (int) ((Math.random() * 10000) % MAX_LIMIT_NUMBER);
Copy link
Member

Choose a reason for hiding this comment

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

JAVA API의 Random 클래스를 사용하면 난수 생성을 쉽게 할 수 있습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

굳이 Random클래스를 사용하여 객체를 추가적으로 생성해야 한다는 것에 의문을 품어 Random 클래스를 사용하지 않았는데 지금와서 생각해보니 성능차이도 없거니와 모두가 주로 사용하는 클래스를 사용해야 가독성이 높아진다는 것을 깨달았습니다.

}
}
106 changes: 106 additions & 0 deletions src/main/java/domain/Validator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package domain;

import io.Printer;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

public class Validator implements ValidatorInterface {
Copy link
Member

Choose a reason for hiding this comment

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

Validator을 따로 선언하여 입력 검증을 하는 책임을 분리하셨군요! 👍

하지만 ValidatorInterface의 추상화의 목적은 무엇인가요?

저도 저번 미션에서 받은 리뷰 내용이지만,
추상화에 명확한 목적이 있다면 중복되는 코드를 줄일 수 있어 효과적입니다.
또한 확장에도 편리하여 자바에서는 다양한 추상화 기법을 지원합니다.

하지만 모든 경우에 있어 과도한 확장을 고려한다면 오히려 필요 이상으로 코드의 양이 많아집니다.
[오버 엔지니어링 참고]

요구사항에 맞춘 추상화 수준으로 작성하고 요구사항의 변경이 있을 때 추상화하셔도 괜찮습니다. 😀

Copy link
Member Author

Choose a reason for hiding this comment

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

사실 이번 과제에서 인터페이스를 사용한 목적은 (미션 내내 페어프로그래밍을 할 수 없기 때문에) 기본 설계구조를 만들어 놓고 각 클래스 내부에 어떤 함수, 변수 등을 사용할 지 선언을 한 다음 따로 코드를 구현해와 비교하기 위해서 사용했습니다. 참고했던 인터페이스 관련 글 이 글을 읽고 협업시 인터페이스를 사용하면 더 편하겠다는 생각을 했어요.

Copy link
Member

Choose a reason for hiding this comment

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

말씀하신 내용을 제가 제대로 이해했다면 객체는 행위 위주로 설계하는 것이 옳은 방식이라 이러한 의도에 있어서 인터페이스를 활용했다면 잘하신 일이라고 말씀드리고 싶습니다.
하지만 협업을 위해 코드를 작성해놓고 필요없다면 나중에 코드를 제거하는 리팩토링 작업이 필요할 것 같습니다.
사실 협업을 위한 인터페이스 정의는 문서로도 충분하니까요 😄

Copy link
Member

Choose a reason for hiding this comment

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

Validator의 용도가 입력을 검증하고 오류 코드를 반환하는 것으로 느껴졌습니다. (물론 오류 코드보다는 true/false가 명확하기는 합니다)

그런 이유로 오류가 발생하는 그 즉시 오류를 검증하는 해당 메서드 내에서 메시지를 출력하는 결과로 나타난 것으로 보입니다. [클린코드 - 오류보다는 예외를 사용하라 참고]

또한 이러한 이유로 테스트 코드에서 Validator 테스트의 결과 검증을 true/false로만 할 수 밖에 없는데
예외를 사용한다면 어떤 이유로 예외가 발생했는지 더 상세한 테스트 코드를 작성할 수 있을 것 입니다.

예외적인 상황에서는 사용자 정의 예외 클래스를 작성해서 예외 처리를 해보세요 😸

private static final int MAX_NAME_SIZE = 5;
private static final String valiNumber = "^[0-9]+$";
private static final String commaInARow = "^.*(,,).*+$";
private static final String characterOTN = "^[a-zA-Z,]+$";
songpang marked this conversation as resolved.
Show resolved Hide resolved
Printer printer;
Copy link
Member

Choose a reason for hiding this comment

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

접근 제한자가 필요할것 같아요!


public Validator() {
printer = new Printer();
}

@Override
public boolean validateName(String s) {
Copy link
Member

Choose a reason for hiding this comment

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

약어를 사용하기보단 적절한 이름을 사용해주세요!

return inputNothing(s)
&& inputCommaInARow(s)
&& inputCharactersOtherThanName(s)
&& startWithComma(s)
&& endWithComma(s)
&& overSizeCharacters(s)
&& inputSameName(s);
}

@Override
public boolean validateNumber(String s) {
Copy link
Member

Choose a reason for hiding this comment

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

boolean을 반환하는 함수의 네이밍은 일반적으로 is, can, should, has 등을 사용합니다.
[참고]

Suggested change
public boolean validateNumber(String s) {
public boolean isValidNumber(String s) {

만으로도 반환 타입이 무엇인지 나타낼 수 있으니 더 좋지 않을까요?

return s.matches(valiNumber);
}

@Override
public boolean inputNothing(String s) {
if (s.equals("")) {
printer.printExceptionMessage("INPUT_NOTHING");
return false;
}
return true;
}

@Override
public boolean inputCommaInARow(String s) {
if (Pattern.matches(commaInARow, s)) { //체크 필요
printer.printExceptionMessage("INPUT_COMMA_IN_A_ROW");
return false;
}
return true;
}

@Override
public boolean startWithComma(String s) {
if (s.charAt(0) == ',') {
printer.printExceptionMessage("START_WITH_COMMA");
return false;
}
return true;
}

@Override
public boolean endWithComma(String s) {
if (s.charAt(s.length() - 1) == ',') {
printer.printExceptionMessage("END_WITH_COMMA");
return false;
}
return true;
}

@Override
public boolean inputCharactersOtherThanName(String s) {
if (!Pattern.matches(characterOTN, s)) {
printer.printExceptionMessage("INPUT_CHARACTERS_OTHER_THAN_NAME");
return false;
}
return true;
}

@Override
public boolean inputSameName(String s) {
List<String> CAR_NAME_LIST = Arrays.asList(s.split(","));
Copy link
Member

Choose a reason for hiding this comment

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

대문자와 언더스코어 조합의 네이밍은 상수 한에서만 적용되는 컨벤션입니다.

int sizeOfNameList = CAR_NAME_LIST.size();

for (int i = 0; i < sizeOfNameList; i++) {
if (CAR_NAME_LIST.subList(i + 1, sizeOfNameList).contains(CAR_NAME_LIST.get(i))) {
printer.printExceptionMessage("INPUT_SAME_NAME");
return false;
}
}
return true;
}

@Override
public boolean overSizeCharacters(String s) {
String[] splitName = s.split(",");
for (String i : splitName)
if (i.length() > MAX_NAME_SIZE) {
printer.printExceptionMessage("OVER_SIZE_CHARACTERS");
return false;
}
return true;
}

}
21 changes: 21 additions & 0 deletions src/main/java/domain/ValidatorInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain;

public interface ValidatorInterface {
boolean validateName(String s);

boolean validateNumber(String s);

boolean inputNothing(String s);

boolean inputCommaInARow(String s);

boolean startWithComma(String s);

boolean endWithComma(String s);

boolean inputCharactersOtherThanName(String s);

boolean inputSameName(String s);

boolean overSizeCharacters(String s);
}
Empty file removed src/main/java/empty.txt
Empty file.
42 changes: 42 additions & 0 deletions src/main/java/io/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io;

import java.util.HashMap;
import java.util.Map;

public class Message implements MessageInterface {
Copy link
Member

Choose a reason for hiding this comment

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

출력 메시지를 한곳에 몰아서 작성하셨네요! 읽기 편한 것 같습니다 👍

다만 사용할 수 있는 메시지의 종류를 열거형으로 정의하면 Message 객체를 사용하는 Validator에서
raw한 String으로 호출하지 않아도 돼서 런타임 에러를 방지할 수 있고, Validator에서 Message에 대한 상세 정보를 몰라도 되는 긍정적인 결과를 낳을 수 있을 겁니다 😄

Map<String, String> generalMessageList = new HashMap<String, String>();
Map<String, String> exceptionMessageList = new HashMap<String, String>();

public Message() {
this.exceptionMessageList();
this.generalMessageList();
}
private void generalMessageList() {
generalMessageList.put("INPUT_NAMEOFCAR", "경주할 자동차 이름을 입력하세요. (이름은 쉼표(,) 기준으로 구분)");
generalMessageList.put("INPUT_COUNT", "시도할 회수는 몇회인가요?");
generalMessageList.put("OPERATION_RESULT", "실행 결과");
generalMessageList.put("FIANL_WINNER", "가 최종 우승했습니다.");
generalMessageList.put("DEFAULT_SPACE", "");
}

private void exceptionMessageList() {
exceptionMessageList.put("INPUT_NOTHING", "아무 문자도 입력되지 않았습니다.");
exceptionMessageList.put("INPUT_COMMA_IN_A_ROW", "쉼표(,)가 연속으로 입력되었습니다.");
exceptionMessageList.put("INPUT_CHARACTERS_OTHER_THAN_NAME", "영어와 쉼표(,) 이외의 다른 문자가 입력되었습니다.");
exceptionMessageList.put("START_WITH_COMMA", "쉼표(,)로 시작합니다.");
exceptionMessageList.put("END_WITH_COMMA", "쉼표(,)로 끝납니다.");
exceptionMessageList.put("INPUT_SAME_NAME", "같은 이름이 입력되었습니다.");
exceptionMessageList.put("OVER_SIZE_CHARACTERS", "이름이 5자 이상입니다.");
exceptionMessageList.put("INPUT_CHARACTERS_OTHER_THAN_DIGIT", "숫자 이외의 다른 문자가 입력되었습니다.");
}
Copy link
Member

Choose a reason for hiding this comment

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

메세지를 Map으로 관리하려는 의도는 무엇이었나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

첫번째는 Key값을 통해 메세지들을 관리하면 효율적일 것 같다는 생각에서였고 이를 통해 클래스를 만들어 관리하면 일괄적으로 관리할 수 있다는 이점이 추가적으로 있을 것 같다는 생각이었습니다!

Copy link
Member

Choose a reason for hiding this comment

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

만약 key값을 통해 관리하게 된다면 "INPUT_NAMEOFCAR" 라는 문자열을 키로하는 것이 아닌, 상수로 만들어서 관리하는 편이 좋을것 같아요!
Message 클래스에 public static final String INPUT_NAME_OF_CAR = "inputNameOfCar";
와 같은 식으로 만든다면 다른 클래스에서도 Message.INPUT_NAME_OF_CAR 로 사용할 수 있을거에요 🙂


@Override
public String selectMessageFromGeneral(String Keyword) {
return generalMessageList.get(Keyword);
}

@Override
public String selectMessageFromException(String Keyword) {
return exceptionMessageList.get(Keyword);
}
}
Loading