Skip to content

[자동차 경주] 박호건 미션 제출합니다.#4

Open
moongua404 wants to merge 8 commits into
Java-JavaScript-Language-Stuty:mainfrom
moongua404:moongua404
Open

[자동차 경주] 박호건 미션 제출합니다.#4
moongua404 wants to merge 8 commits into
Java-JavaScript-Language-Stuty:mainfrom
moongua404:moongua404

Conversation

@moongua404
Copy link
Copy Markdown
Contributor

🏎️ 자동차 경주 🏎️

언어 스터디 2주차 미션 PR입니다!

1. 신경써서 구현한 부분

의존성 관리

  • AppConfig 파일을 통해 의존성을 통합관리 했습니다.
  • 입력을 인터페이스로 제공해 의존성을 분리하여 단위테스트를 진행했습니다.
  • 랜덤 로직을 모델과 분리한 후 매개변수로 전달했습니다.
  • MVC 패턴으로 각 계층의 역할에 맞춰 구현했습니다.

2. 피드백이 필요한 부분

제가 부족한 부분은 무엇이든 피드백받고싶습니다.

  • 객체지향적인지
  • 역할 분리가 적절한지
  • 변수명 / 함수명이 직관적인지
  • 요구 사항에 맞지 않는 부분이 있는지

3. 내가 고려한 예외

  • 이름 길이 검증
  • 이름 빈 값 검증
  • 시도횟수 양수 검증
  • 이름 중복 검증

- 과제 내용, 코드 흐름, 구현 기능 목록 작성
- 코드 흐름에서 flow diagram 작성
- MVC 패턴에 맞춰 패키지 구성
- AppConfig 클래스 생성
- InputProvider 인터페이스로 의존성 분리
- 테스트 코드 작성
- Race 모델을 통해 게임 전반 관리
- 이동 여부(랜덤 로직) Suplier로 의존성 분리
- 테스트코드 작성 (예제 모킹)
- 컨트롤러를 통해 뷰와 서비스를 이음
- 서비스를 통해 모델과 이음
- Appconfig를 통해 의존성 주입
- OutputView에 개행 메서드 추가
- 이름 길이 유효성 검사
- 빈 입력 / 빈 이름 유효성 검사
- 중복된 이름 유효성 검사
- 시도 횟수 유효성 검사
- 숫자 및 구분자 상수 분리
Copy link
Copy Markdown

@daeGULLL daeGULLL left a comment

Choose a reason for hiding this comment

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

이번에도 실력이 드러나는 멋진 코드였습니다. provider랑 테스트하는방법 퍼가요~~^^

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

지금 보니까 서비스가 상호작용하는 모델이 race밖에 없고 race가 car의 함수를 다 커버하는것 같은데, 그러면 race가 모델보다는 서비스에 가깝지 않나유??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

책임을 분리하기 위함입니다. 서비스 레이어가 필요한 이유는 여러 모델을 중계하기 위함도 있을 수 있지만 컨트롤러의 비지니스 로직과 데이터와 이에 대한 상태를 담아두는 모델을 분리하는 것 역시 있다고 생각합니다.
경주에서는 각 경주용 차는 매 턴마다 정지하거나 1의 위치 만큼 이동한다., 우승자는 한 명 이거나 여러명일 수 있다. 등과 같은 규칙이 내재되어있기에 이것이 프로그램의 전체 진행을 관리하는 비지니스 로직에 포함될 경우, MVC 패턴에서 서비스 레이어의 책임이 과중되고, 이에 무결성을 관리하는데 어려움을 겪을 수 있다고 생각했기 때문입니다.

public class CarControlService {
private Race race;

private static final int MIN_CHAR_LENGTH = 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static final min max값은 카 컨트롤 서비스보단 validator랑 관련이 있는거같은데 validator에 넣으시는게 나을듯 유틸 클래스는 stateless해야하지만 상수값은 가질 수 잇다구 검색하면 나옵니다

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

상수가 몇 개 없어 상수 파일을 만들지는 않았지만 그것 이외의 문제가 되지는 않다고 생각합니다. (static final로 선언하여 상수화시켰기에 이 부분은 stateless합니다. )
Validator에 넣지 않은 이유는 관심사를 분리하기 위함입니다. Validator는 재사용성이 높고 유연한 구조를 가져야 하기에 더욱 경주용 차의 도메인인 "이름의 길이"와 같은 상수가 들어가기에 부적절하다고 생각합니다. 이를 자동차 관리 서비스의 상수로 두는 것이 관리/유지보수성 측면에서도 좋을 것이라고 생각합니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

오호 저는 validator의 stringRangeCheck가 이름만 관리하는걸로 생각해서 상수를 내부에 집어넣는걸 코멘트했었는데 호건씨 사용처쪽으로 생각하시면 해당 방안이 더 적합하다구 생각합니다!!

public static void stringRangeCheck(String input, int min, int max) {
if (input.length() <= min || input.length() > max) {
throw new IllegalArgumentException("[Error] Invalid character length.");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MessageConstants처럼 에러도 enum으로 빼면 더 조을것 같아요

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(단순한 궁금증) observer를 안쓰시는 이유가 잇나요잉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

쓸 필요성을 못느끼기 때문입니다. 컨트롤러에서 직접 데이터를 주고받아도 충분하다고 생각합니다. 웹사이트에서, UI로 하는 상호작용 등의 경우라면 모델의 변화에 따라 뷰가 민감하게 바뀌어야겠지만 터미널을 인터페이스로 쓰는 경우 그러한 경우가 없기에 도입할 필요가 약해 보이기 때문입니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

오호 그렇군요 하긴 저두 옵저버만 써야한다보다는 연습하려고 도입하고 있습니다. 콘솔에 하기에는 좀 굳이 싶긴하죠ㅎㅎ

}

public void run() {
initialize();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

제 개인적인 생각으론 저 런 메소드는 메인에 빼는게 더 좋을거같아요 컨트롤러는 사용자의 조작에 따라 처리하는 놈이라 시스템 전체 실행에는 관련이 약하지 않나용??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

initialize 메서드 말씀하시는거죠? 이 메서드는 단순히 "프로그램 초기화를 위한 것"이라기 보다는 "자동차 경주를 준비"하는 개념에 가깝다고 생각해요! 필연적으로 뷰와 모델을 매개하기에 컨트롤러의 역할이라고 바라봤습니다

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.

2 participants