-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2단계 - 자동차 경주 리팩터링] 테오(최우성) 미션 제출합니다. (#590)
* refactor: 우승자 반환 시 자동차가 없는 경우 디테일한 예외를 던지도록 변경 * refactor: 상수 필드를 모두 static final로 변경 * refactor: 예외메세지 출력을 View의 책임으로 변경 * refactor: OutputView을 ConsoleView로 리네이밍 * refactor: 시도 횟수 검증 메소드 네이밍을 이해하기 쉽도록 수정 * refactor: 자동차 비교 시 getter를 사용하지 않도록 수정 * refactor: 자동차 이름 VO 생성 * refactor: 자동차 이름 객체 getter명 변경 * refactor: 자동차 위치 정보를 관리하는 VO 생성 * refactor: 자동차 위치를 외부에서 주입받도록 수정 * refactor: 시도 횟수를 객체로 다루도록 수정 * refactor: 우승자 테스트 로직에 가독성 부여 * docs: 변경사항 및 고민사항 기재 * refactor: 코인을 사용할 때 유효성 검증 추가 * refactor: getter 명을 이해하기 쉽도록 변경 * refactor: 커스텀 예외를 사용해 도메인에서 뷰 의존성 제거
- Loading branch information
1 parent
1c6a0d3
commit 7c282e4
Showing
19 changed files
with
257 additions
and
105 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import controller.RacingController; | ||
import view.input.InputView; | ||
import view.output.OutputView; | ||
import view.output.ConsoleView; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
new RacingController(new InputView(scanner), new OutputView()).start(); | ||
new RacingController(new InputView(scanner), new ConsoleView()).start(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package domain; | ||
|
||
import exception.CarNameBlankException; | ||
import exception.CarNameLengthException; | ||
|
||
public class CarName { | ||
|
||
private static final int MAX_CAR_NAME_LENGTH = 5; | ||
|
||
private final String carName; | ||
|
||
public CarName(String carName) { | ||
validateCarName(carName); | ||
this.carName = carName; | ||
} | ||
|
||
private void validateCarName(String carName) { | ||
validateCarNameIsNotEmpty(carName); | ||
validateCarNameLength(carName); | ||
} | ||
|
||
private void validateCarNameIsNotEmpty(String carName) { | ||
if (carName.isBlank()) { | ||
throw new CarNameBlankException(); | ||
} | ||
} | ||
|
||
private void validateCarNameLength(String carName) { | ||
if (carName.length() > MAX_CAR_NAME_LENGTH) { | ||
throw new CarNameLengthException(); | ||
} | ||
} | ||
|
||
public String getCarName() { | ||
return carName; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package domain; | ||
|
||
public class Coin { | ||
|
||
private int remaining; | ||
|
||
public Coin(int remaining) { | ||
this.remaining = remaining; | ||
} | ||
|
||
public void use() { | ||
if (isLeft()) { | ||
remaining--; | ||
} | ||
} | ||
|
||
public boolean isLeft() { | ||
return remaining > 0; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package domain; | ||
|
||
import exception.PositionInvalidException; | ||
|
||
public class Position { | ||
|
||
private int position; | ||
|
||
public Position(int position) { | ||
validatePosition(position); | ||
this.position = position; | ||
} | ||
|
||
private void validatePosition(int position) { | ||
validatePositionIsNotNegative(position); | ||
} | ||
|
||
private void validatePositionIsNotNegative(int position) { | ||
if (position < 0) { | ||
throw new PositionInvalidException(); | ||
} | ||
} | ||
|
||
public void moveForward() { | ||
position++; | ||
} | ||
|
||
public int getPosition() { | ||
return position; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package exception; | ||
|
||
public class CarNameBlankException extends RuntimeException { | ||
|
||
private static final String MESSAGE = "[ERROR] 자동차의 이름은 공백이면 안됩니다."; | ||
|
||
public CarNameBlankException() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package exception; | ||
|
||
public class CarNameLengthException extends RuntimeException { | ||
|
||
private static final String MESSAGE = "[ERROR] 자동차 이름의 길이는 1자 이상, 5자 이하여야 합니다."; | ||
|
||
public CarNameLengthException() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package exception; | ||
|
||
public class NoCarsExistException extends RuntimeException { | ||
|
||
private final static String MESSAGE = "[ERROR] 자동차가 존재하지 않습니다."; | ||
|
||
public NoCarsExistException() { | ||
super(MESSAGE); | ||
} | ||
} |
Oops, something went wrong.