[자동차 경주 게임] 박세민 미션 제출합니다.#5
Open
semInDev wants to merge 15 commits intowoowa-precourse-study:mainfrom
Open
Conversation
- `CarNameVerifier` → `CarNameValidator` - `RoundVerifier` → `RoundValidator` - `WinnersFinder` → `WinnerCalculator` - `RacingCarService.playRacingCar()` → `startRace()`
- 출력(System.out)을 Service에서 제거 → ResultView에서 전담 - 랜덤 이동 로직을 Mover 인터페이스로 분리 (테스트 가능 구조) - carName을 final로 -> Car 클래스 불변성 강화 - 매직 넘버 -> 상수 처리
Member
Author
컴포넌트 설명Controller Layer
Domain Layer
Service Layer
View Layer
신경 쓴 부분객체지향 설계
확장 가능한 구조
|
khcho96
reviewed
Sep 27, 2025
|
|
||
| public interface Mover { | ||
| boolean canMove(); | ||
| } |
| System.out.println("실행 결과"); | ||
| for (List<Car> round : raceHistory) { | ||
| for (Car car : round) { | ||
| System.out.println(car.getCarName() + " : " + "-".repeat(car.getPosition())); |
Collaborator
There was a problem hiding this comment.
저는 결과값을 문자열에 모두 담아서 출력했는데, Car 객체 안에 레이싱 과정의 모든 정보를 담아서 처리하면 더 좋았을 뻔 했네요!
| this.position = position; | ||
| } | ||
|
|
||
| public String getCarName() { |
Collaborator
There was a problem hiding this comment.
pr_checklist.md에 따르면 getter를 쓰지 않고 구현하는 게 좋다고 하는데, 세민님은 어떻게 생각하시는지 궁금합니다. getter 쓰지 않고 머리 굴리려니 힘들더라구요..ㅎ
| for (Car car : cars) { | ||
| if(maxPosition < car.getPosition()){ | ||
| maxPosition = car.getPosition(); | ||
| winners.clear(); |
Collaborator
There was a problem hiding this comment.
만약 winners 리스트의 크기가 크다면 O(n)의 clear 메서드보다 new ArrayList<>()로 상수시간에 처리하면 성능 면에서 더 좋을 것 같아요!
Member
Author
Strategy Pattern에 대해 더 정리
public interface MoveStrategy {
boolean movable();
}
---
public class RandomMoveStrategy implements MoveStrategy {
private final Random random = new Random();
@Override
public boolean movable() {
return random.nextInt(10) >= 4;
}
}
// 나중에 테스트 시에 AlwaysMoveStrategy를 사용하여 테스트를 용이하게 할 수 있음!
public class AlwaysMoveStrategy implements MoveStrategy {
@Override
public boolean movable() {
return true;
}
}
---
public class Car {
// 컨텍스트인 Car는 Move 전략(구체적인 알고리즘)을 몰라도 됨.
// 실제 알고리즘은 주입된 전략 객체가 결정
private final String name;
private int position = 0;
private final MoveStrategy moveStrategy;
public Car(String name, MoveStrategy moveStrategy) {
this.name = name;
this.moveStrategy = moveStrategy;
}
public void move() {
if (moveStrategy.movable()) {
position++;
}
}
}1. 장점
2. 단점
3. 자동차 경주 게임 예시
|
Collaborator
|
친절한 정리 감사합니다!!!😆👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. 구현 기능 목록
1. 입력 기능
2. 입력 검증 기능
IllegalArgumentException발생IllegalArgumentException발생3. 자동차 도메인 기능
4. 게임 진행 기능
5. 출력 기능
6. 전체 애플리케이션 제어 기능
2. 기술적 구현 사항
객체지향 설계
데이터 관리