-
Notifications
You must be signed in to change notification settings - Fork 453
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
[2단계 - 자동차 경주 리팩터링] 테오(최우성) 미션 제출합니다. #590
Changes from all commits
f48daf2
89cb13a
20f96b4
cd556c7
b505edf
cb18855
fc80f72
a105917
1e1d002
818ea37
104dde3
42373a9
75a4012
4d5ac66
cee3f17
df57ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
} | ||
} |
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; | ||
} | ||
} |
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use() 이전에 isLeft() 검사를 해주는 것도 좋을것 같네요. |
||
if (isLeft()) { | ||
remaining--; | ||
} | ||
} | ||
|
||
public boolean isLeft() { | ||
return remaining > 0; | ||
} | ||
} |
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; | ||
} | ||
} |
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] 자동차의 이름은 공백이면 안됩니다."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분도 결국엔 도메인이 어떤 메세지를 노출시켜야할지 정하는 구조이지 않을까요? 고민해보시고 마땅한 방법이 떠오르지 않으신다면 DM 주세요 |
||
|
||
public CarNameBlankException() { | ||
super(MESSAGE); | ||
} | ||
} |
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); | ||
} | ||
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VO라는 용어를 사용하셔서 질문드려요 :)
Coin은 VO라고 생각하고 모델링 하신걸까요?
VO (Value Object) 이외엔 어떠한 유형의 객체 모델이 존재하나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CarName이나 Position은 VO라고 생각하지만, Coin객체는 VO라고 생각하지 않았습니다!
제가 생각하는 VO의 정의는 다음과 같습니다.
본래 객체로 나타내지 않아도 될 값들을 제약조건이나 동등성 비교를 위해 객체로 다루는 것
즉, 어떤 값들을(돈, 나이, 개수 등) 원시형으로 다룰 수도 있겠지만,
일부러 객체로 구성해 의미를 부여하는 것이 Value Object의 목적이라고 생각했습니다.
Coin 객체는
remaining
이 같다고 해도 같은 객체라고 보장할 수 없고,값을 나타내기 위해 탄생한 객체
가 아니기 때문에 VO라고 생각하지 않았습니다.또한 조사해 본 결과, VO 이외에 DTO, DAO, Entity, PO, BO, SO 등의 객체 모델이 존재하는 것 같습니다..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(전 VO같아요 🙃)
이 부분에 대해선 따로 더 의견 드리진 않겠습니다 :)
용어에 대한 해석이 제 각각이고, 각자의 해석에 따라 여러 자료들이 재생산되다보니 여러 개념이 뒤섞이게 되는것 같은데요.
이 부분은 고민해보면서 테오 나름의 개념을 만들어 가셨으면 좋겠습니다.
그리고 말씀주신 유형중, VO와 같은 선상에 놓고 비교해야하는 객체는 Entity라고 생각합니다. (PO, BO, SO는 처음 들어보네요. 저도 공부해볼게요)