-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Step5 (MVC 리팩토링) 리뷰 요청드립니다. #913
Changes from all commits
ccf4b29
0ed4e45
12b4e41
1e29191
e033fb1
949cd10
529b139
1133907
768661d
ead5131
73a721a
aacf4f3
d6e4e45
b695493
ee65186
d6b2f18
8bc2807
0cfccce
180451f
cc47dec
47eb163
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package step5.racingcar; | ||
|
||
import step5.racingcar.controller.RacingGameController; | ||
import step5.racingcar.view.InputView; | ||
import step5.racingcar.view.ResultView; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
InputView inputView = new InputView(); | ||
ResultView resultView = new ResultView(); | ||
RacingGameController racingGameController = new RacingGameController(inputView, resultView); | ||
|
||
racingGameController.processUserInputs(); | ||
racingGameController.startGame(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,24 @@ | |
* 자동차 객체의 Position을 이동시키기는 기능. | ||
* 경기 결과를 출력하는 기능. | ||
* 가장 멀리 주행한 자동차들의 리스트를 가져오고 출력하는 기능. | ||
|
||
## MVC 기반 리팩토링 | ||
|
||
* Domain | ||
* Car | ||
* CarFactory | ||
* CarGroups | ||
* RacingGame | ||
* MovingStrategy | ||
* RandomMovingStrategy | ||
* Message | ||
|
||
* Controller | ||
* RacingGameController | ||
Comment on lines
+27
to
+28
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. 이런 패키지 분리 등은 개인의 의도와 네이밍이 다 달라서 리뷰를 남기기 조심스러운데, 제가 생각했던 내용을 간단히 코멘트 남길게요 참고만 하시고 변경은 하시지 않아도 될 것 같아요 기존 Controller가 없을 때 Main에서 InputView를 호출해 입력을 받고, domain의 RacingGame을 이용해 결과를 받고, ResultView를 이용해 결과를 출력해주고 있었던걸로 기억합니다. 저는 그래서 이미 Main 자체가 Controller의 역할을 수행하고 있지 않았나? 하는 생각이 조금 들었어요! 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. 아 네 맞습니다. Main 자체가 Controller 역할을 하고 있었는데요. |
||
|
||
* View | ||
* InputView | ||
* ResultView | ||
|
||
* Application | ||
* Main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package step5.racingcar.controller; | ||
|
||
import step5.racingcar.domain.Message; | ||
import step5.racingcar.domain.RacingGame; | ||
import step5.racingcar.view.InputView; | ||
import step5.racingcar.view.ResultView; | ||
|
||
public class RacingGameController { | ||
|
||
private RacingGame racingGame; | ||
private final InputView inputView; | ||
private final ResultView resultView; | ||
|
||
public RacingGameController(InputView inputView, ResultView resultView) { | ||
this.inputView = inputView; | ||
this.resultView = resultView; | ||
} | ||
|
||
public void processUserInputs() { | ||
String[] carNames = inputView.getCarNames(Message.CAR_NAMES); | ||
int gameTryCounts = inputView.getGameTryCounts(Message.GAME_TRY_COUNTS); | ||
this.racingGame = new RacingGame(carNames, gameTryCounts); | ||
} | ||
|
||
public void startGame() { | ||
if (racingGame == null) { | ||
throw new IllegalStateException(Message.ERROR_INVALID_ORDER); | ||
} | ||
resultView.printResultHeader(Message.RESULT_HEADER); | ||
while (racingGame.hasNextRound() == true) { | ||
racingGame.run(); | ||
resultView.printResult(racingGame); | ||
} | ||
resultView.printWinnerCarNames(racingGame); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package step3.racingcar; | ||
package step5.racingcar.domain; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package step3.racingcar; | ||
package step5.racingcar.domain; | ||
|
||
public interface MovingStrategy { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package step3.racingcar; | ||
package step5.racingcar.domain; | ||
|
||
import java.util.Random; | ||
|
||
|
This file was deleted.
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.
먼저 남겨주신 내용에 대해 먼저 답변 드리고 리뷰를 시작할게요!
Car가 이동 규칙을 가지는 경우
Car 객체의 position이 명확히 움직이는지를 확인하는 테스트는 전략 패턴을 활용하셨으니 이동 규칙을 갈아끼워 주는 방식으로 테스트를 진행하시면 괜찮지 않을까요?
MovingStrategy
는 FunctionalInterface라 람다를 이용해 Car 객체가 가지는 이동 규칙을 쉽게 바꿀 수 있을 것 같습니다.Car의 단위 테스트에서 생성자로 테스트에서 정의한 새로운 MovingStrategy(무조건 이동한다거나..)를 만들어 테스트에 활용해보시면 어떨까요?
RaingGame이 Car의 이동 규칙을 가지는 경우
추가로 RacingGame의 규칙을 Car에게 전달하는 방식으로 사용한다고 하셔도 MovingStarategy가 RacingGame의 내부에 캡슐화되어 RacingGame 내부의
move
메소드에 대한 테스트는 여전히 힘들것 같습니다.지금 구조로 진행하신다고 하면 RacingGame의 생성자로 MovingStrategy를 받고 테스트에서 RacingGame 생성 시점에 이동 전략을 교체해주는 방식으로 move까지 통합적인 테스트를 하고, 실제 어떤 자동차가 가장 멀리 이동했는지, 우승자가 누군지를 구하는 방법까지 테스트해주실 수 있을 것 같네요
조금 이건 개인적인 견해일 수 있는데요 , Car 각각의 이동 전략을 RacingGame이 통합적으로 컨트롤해주는 것 보다 그 각각의 이동 전략을 Car에 위임하는 방식이 조금 더 자연스럽다고 생각이 듭니다. (각각 Car 마다 이동 전략이 다를수도 있고.. Car 자기 자신이 이동하는데 이동에 대한 규칙을 외부에서 받는게 조금 부자연스러운 생각이 들어서요)
하지만 지금의 요구사항 안에서라면 RacingGame이 이동 규칙을 가지고 각각 자동차 이동 시 마다 규칙을 넘겨주어 이동 여부를 체크하고 각각의 자동차를 이동시키는 방법이 조금 더 효율적인 것 같긴 합니다.
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.
자세한 피드백 감사합니다. 그런 방식으로도 테스트가 가능하겠군요!!