[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ์ฐ๋ ๋ฏธ์ ์ ์ถํฉ๋๋ค.#274
[๐ ์ฌ์ดํด2 - ๋ฏธ์
(๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ์ฐ๋ ๋ฏธ์
์ ์ถํฉ๋๋ค.#274armd482 wants to merge 29 commits intowoowacourse:armd482from
Conversation
Chocochip101
left a comment
There was a problem hiding this comment.
์๋
ํ์ธ์, ์ฐ๋! โ๐ป ๋ฆฌ๋ทฐ์ด ์ด์ฝ์นฉ์
๋๋ค ๐ช
์ฌ์ดํด 1์ ์ด์ด ์ฌ์ดํด 2๋ ์ ๊ตฌํํด์ฃผ์
จ๋ค์.
๋ฆฌ๋ทฐ ๋จ๊ฒผ์ผ๋ ํ์ธํด๋ณด์๊ณ , ์ฌ์์ฒญ์ฃผ์ธ์ ๐
|
|
||
| Side winnerSide = game.getWinnerSide(); | ||
|
|
||
| if(winnerSide == null) { |
There was a problem hiding this comment.
- null์ด ๋ ์ ์๋์? Side.Empty๋ฅผ ๋ฐํํ์ง ์๋์?
- null๋ก ๋ค๋ฃจ๋๊ฒ ๋ง๋์?
- ํด๋น ๋ก์ง์ game์์ ๋ค๋ฃฐ ์ ์๋์? (game.hasXXX()?๊ฐ์)
- ํด๋น ๋ก์ง์ ํ ์คํธ๋ก ์ปค๋ฒ ๋์๋์?
| - ์์ ์ ์ด/ํ ์ง์์ ๊ธฐ๋ณธ ๊ธฐ๋ฌผ ๋ฐฐ์น์ ๋ง์ ๋ฐฐ์น๋ฅผ ๋ฐ์ํด ์ด๊ธฐํํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ํ์ฌ ์์น์ ๊ธฐ๋ฌผ ์กฐํ, ๋น ์นธ ์ฌ๋ถ, ์๊ตฐ/์ ๊ตฐ ์ฌ๋ถ๋ฅผ ํ๋จํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ๊ธฐ๋ฌผ ์ด๋ ์์ฒญ์ ๋ฐ์ ์ค์ ์ํ๋ฅผ ๋ณ๊ฒฝํ๋ค. | ||
| - ์ฅ๊ธฐํ์ ์๋ ๊ธฐ๋ฌผ์ ์ก์์ ๋ ํด๋น ์ง์์ ์ ์๋ฅผ ์ค์๊ฐ์ผ๋ก ์ฐจ๊ฐํ๋ค. |
| return new TurnState(new FinishTurn(board, Side.HAN, turn), turnAttribute, pieceAttribute); | ||
| } | ||
|
|
||
| TurnAttribute turnAttribute = new TurnAttribute(Side.HAN, turn + 1); |
There was a problem hiding this comment.
HAN ๋ค์์ CHO๋ฅผ ๋ฐํํด์ผํ์ง ์๋์?
| TurnAttribute turnAttribute = new TurnAttribute(Side.HAN, turn + 1); | |
| TurnAttribute turnAttribute = new TurnAttribute(Side.CHO, turn + 1); |
ํ ์คํธ๋ก ์ปค๋ฒ๊ฐ ๋์์๊น์?
| PieceAttribute pieceAttribute = board.move(start, end, Side.HAN); | ||
|
|
||
| if(turn == MAX_TURN) { | ||
| TurnAttribute turnAttribute = new TurnAttribute(Side.EMPTY, turn + 1); |
There was a problem hiding this comment.
ChoTurn๊ณผ ๋๊ธฐ๋ ์ธ์๊ฐ ๋ค๋ฅธ๋ฐ, ์ด๋ค๊ฒ ๋ง๋์?
| SideScore score = game.getCurrentSideScore(); | ||
| if(score.cho() > score.han()) { |
There was a problem hiding this comment.
getter๋ก ๊บผ๋ด์์ ๋น๊ตํด์ผํ๋์?
| OutputView.printLine(); | ||
|
|
||
| MoveResult moveResult = game.move(startPosition, endPosition); | ||
| TurnDto turnDto = new TurnDto(moveResult.turnAttribute().side().getName(), moveResult.turnAttribute().turn()); |
There was a problem hiding this comment.
๋๋ฏธํฐ ๋ฒ์น ์๋ฐ์ด๋ค์. ์ด๋ป๊ฒ ๊ฐ์ ํด๋ณผ ์ ์์๊น์?
ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ: ํ ์ค์ ์ ์ ํ๋๋ง ์ฐ๋๋ค.
| game = new Game(choArrangement, hanArrangement); | ||
| } | ||
| List<PieceDto> pieceDtos = game.init(choArrangement, hanArrangement).stream() | ||
| .map(pieceInitInfo -> new PieceDto(pieceInitInfo.position().getX(), pieceInitInfo.position().getY(), pieceInitInfo.pieceType().getName(), pieceInitInfo.side().getName())) |
There was a problem hiding this comment.
PieceDto์์ ์ ์ ๋ฉ์๋๋ฅผ ๋ง๋ค์ด๋ ์ข์ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ป๊ฒ ์๊ฐํ์๋์?
| .map(pieceInitInfo -> new PieceDto(pieceInitInfo.position().getX(), pieceInitInfo.position().getY(), pieceInitInfo.pieceType().getName(), pieceInitInfo.side().getName())) | |
| .map(PieceDto::from) |
| } | ||
|
|
||
| private Optional<Integer> getPreviousBoard() { | ||
| GameInfos gameInfos = new GameInfos(janggiService.getEntireGame().stream() |
There was a problem hiding this comment.
์ฌ๊ธฐ๋ ๋น์ทํ๊ฒ ์ ์ฉํ ์ ์๊ฒ ๋ค์.
|
|
||
| GameInfo selectedGame = askUntilValid(() -> getSelectedGame(gameInfos)); | ||
|
|
||
| List<PieceInitInfo> pieceInitInfos = janggiService.getPieceInitInfos(selectedGame.id()).stream().map(pieceDto -> new PieceInitInfo(new Position(pieceDto.x(), pieceDto.y()), Side.from(pieceDto.side()), |
There was a problem hiding this comment.
| @@ -23,20 +25,27 @@ | |||
| - ์ขํ๋ ์ ๋ ฅ๊ฐ์ ๊ฒ์ฆํ์ฌ ์์ฑํ๋ค. | |||
There was a problem hiding this comment.
๊ณ์ธต๊ณผ ์ญํ
๋น์ฐํ ์ด๋ ํ ์ ๋ต์ ์๋๊ฒ ์๋๊ธฐ์ ์ ์ ๊ธฐ์ค์ ์๊ธฐํ ๊ฒ์. ์ ๋ ํ์์ ์ํด ์ฐ๋ ๊ฒ ๊ฐ์์. ์๋ฌด๋๋ view์ ๋ณ๊ฒฝ์ด ๋ง๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์ controller์์ view๋ก ๋์ด๊ฐ ๋๋ DTO๋ฅผ ์ฌ์ฉํ๋๋ฐ, DAO์ ์๋น์ค ์ฌ์ด์๋ ์ฃผ๋ก ์ฐ์ง ์์์. ์๊ฐ๋ณด๋ค DAO์ ๋ณ๊ฒฝ์ ์ ์ค์ ๊ฐํ๊ธฐ ๋๋ฌธ์ ์๋น์ค์ ๋ณ๊ฒฝ์ผ๋ก ์ธํด DAO๊ฐ ๋ณํ๋ ๊ฒฝ์ฐ๊ฐ view-controller์ ๋นํด ์ ๊ธฐ ๋๋ฌธ์ด์์. ๋๊ฒจ์ผ ๋๋ ์ธ์๊ฐ ๋ง์ผ๋ฉด ํ์ํ๋ค๊ณ ๋๊ปด์ ์ฐ๊ธฐ๋ ํ๊ณ ์.
์ถ๊ฐ๋ก, ๋ ์ด์ด ๊ฐ ์์กด ๋ฐฉํฅ์ ์งํค๊ธฐ ์ํด DTO๋ฅผ ์ฐ๋ ๊ฒฝ์ฐ๋ ์์ด์. ๋๋ฉ์ธ ๊ฐ์ฒด๋ฅผ DAO๊น์ง ๊ทธ๋๋ก ์ ๋ฌํ๋ฉด DAO๊ฐ ๋๋ฉ์ธ ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ์์์ผ ํ๊ณ , DB ์คํค๋ง๊ฐ ๋ฐ๋์์ ๋ ๋๋ฉ์ธ ๊ฐ์ฒด๊น์ง ์ํฅ์ด ์ ํ๋ ์ ์๊ฑฐ๋ ์. DTO๊ฐ ๋ ๋ ์ด์ด ์ฌ์ด์ ๊ฒฝ๊ณ๋ฅผ ๋ช ์์ ์ผ๋ก ๋ง๋ค์ด์ ์๋ก ๋ ๋ฆฝ์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์๊ฒ ํด์ค ์๋ ์์ด์.
ํ ์คํธ ๋จ์
- ์ด๋๊น์ง ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ๋ ๊ฒ ๋ง์ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค: ์์ฑํ ์ฝ๋์ ๋ชจ๋ ๋ถ๋ถ์ ํ ์คํธํ ์ ์๋์? ๋ถ๊ฐ๋ฅํ๊ฑฐ๋ ํ์์๋ ๋ถ๋ถ์ด ์์๊น์?
- ์ด๋ ๋ถ๋ถ์ ํ ์คํธ ํด์ผํ ์ง์ ๋ํ ๊ณ ๋ฏผ์ด ์์ต๋๋ค: ์ฌ์ฉ์์ Use case๋ถํฐ ์ ๊ทผํด๋ณด๋๊ฑด ์ด๋ค๊ฐ์? ์ ํ๋ฆฌ์ผ์ด์ ์์ ์, ๊ฒ์์ ์์ฑํ๋ฉด ์ ์ฅ์ด ๋๋๊น '๊ฒ์์ด ์ ์ฅ๋๋ค'๋ถํฐ ์์ํด๋ณผ ์ ์๊ฒ ๋ค์.
There was a problem hiding this comment.
์ ์ฒด์ ์ผ๋ก ํ ์คํธ๊ฐ ๋ถ์กฑํ ๊ฒ ๊ฐ์ต๋๋ค! ๋ชจ๋ ์ผ์ด์ค์ ๋ํด ํ ์คํธ๊ฐ ์ปค๋ฒ๋์๋์ง ํ์ธ ๋ถํ๋๋ฆด๊ฒ์!
์ฒดํฌ ๋ฆฌ์คํธ
test๋ฅผ ์คํํ์ ๋, ๋ชจ๋ ํ ์คํธ๊ฐ ์ ์์ ์ผ๋ก ํต๊ณผํ๋์?์ด๋ค ๋ถ๋ถ์ ์ง์คํ์ฌ ๋ฆฌ๋ทฐํด์ผ ํ ๊น์?
์๋ ํ์ธ์ ์ด์ฝ์นฉ.
์ด์ ์ฌ์ดํด์์ ๋จ๊ฒจ์ฃผ์ ๋ฆฌ๋ทฐ๋ค ๋ฐ์ํด์ pr์ฌ๋ฆฝ๋๋ค!
db๊ด๋ จ ์ด๋์ ๋ฐ์ดํฐ๋ฅผ wrappingํ ์ง์ ๋ํ ๊ธฐ์ค์ ์ ๋ชฐ๋ผ์, ์ผ๋จ ์ปจํธ๋กค๋ฌ์์ dto๋ฅผ ์์ฑํ๋ ์์ผ๋ก ๊ตฌํํ์ต๋๋ค.
๊ณ์ ํผ์ ๊ณ ๋ฏผํ๋ ๊ฒ๋ณด๋ค ์ผ๋จ pr์ฌ๋ฆฌ๊ณ ์ฝ๋ฉํธ ๋ฐ์ ๊ฑธ๋ก ๊ณ ๋ฏผํ๋ ๊ฒ ๋ ์ข์ ๊ฒ ๊ฐ์์ ๋ถ์กฑํ์ง๋ง pr์ฌ๋ฆฝ๋๋ค!
๊ณ์ธต๊ณผ ์ญํ
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ์ด ์ฒ์์ด๋ผ ๊ณ์ธต์ ๋ํ ๊ณ ๋ฏผ์ ๋ง์ด ํ ๊ฒ ๊ฐ์ต๋๋ค.
dto๋ผ๋ ๊ฒ ์ฌ์ฉํ๋ ๊ฒ ๋ง๋์ง, ์ฌ์ฉํ๋ค๋ฉด ์ด๋์ ์์ฑํ์ฌ ์ด๋๊น์ง ์ ๋ฌํด์ผ ํ๋์ง, ์ด ๋ถ๋ถ์ด ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
runner -> ์๋น์ค -> dao์์, ์๋น์ค๋ผ๋ ๊ณ์ธต์์ dto๋ฅผ ๋ฐ๋์ง, vo๋ฅผ ๋ฐ์์ผ ํ๋ ์ง, dao์๋ ์์๊ฐ์ผ๋ก ์ ๋ฌํด์ผ ํ๋์ง, ์๋ dto๋ก ์ ๋ฌํด์ผ ํ๋์ง
๋ฐ๋๋ก dao -> service ->runner์์ ์๋น์ค๋ ๊ฐ ์์ฒด๋ฅผ ๋ฐ์์ vo๋ก ์ ๋ฌํ ์ง, dto๋ก ์์ฑํด์ผ ํ ์ง ๊ธฐ์ค์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
ํ ์คํธ ๋จ์
์๋น์ค, TransactionManger,SQL manager, dao์ ๋ํด์ ์ด๋๊น์ง ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ๋ ๊ฒ ๋ง์ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
ํ ์คํธ๋ฅผ ์์ฑํ๋ค๋ฉด, ์ด๋ ๋ถ๋ถ์ ํ ์คํธ ํด์ผํ ์ง์ ๋ํ ๊ณ ๋ฏผ์ด ์์ต๋๋ค