-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด1 - ๋ฏธ์ (๋ณด๋ ์ด๊ธฐํ + ๊ธฐ๋ฌผ ์ด๋)] ๋ชจ์ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #259
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
base: picetea44
Are you sure you want to change the base?
Changes from all commits
cb93bfc
0f8fb4d
ec1afcb
81434bd
4a7f437
ee11a83
b91473b
5ce6271
9198a53
7e8456c
9179f23
68304cd
0d17919
ccfa0e4
95ed613
212f889
b586fd8
f1ee429
bf366d0
6db9326
fbb1143
99c9e0e
55ee04d
b387b44
06de619
e8388ee
804af3d
08f237b
3d7803c
91ee3f1
6f4a476
9dec8bf
45de3b0
9dbbbdd
16ad9c7
7bc74d0
5343fff
036506b
78593ee
32db79b
7ef7e9d
ccae384
494396b
168cc30
b526872
726d94c
28ebeff
745799b
8bcf443
9c423a6
b1455ff
e73c692
d151d75
92b4ee9
2466494
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,3 +1,40 @@ | ||
| # java-janggi | ||
| ## ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ ์ฒดํฌ๋ฆฌ์คํธ | ||
|
|
||
| ์ฅ๊ธฐ ๋ฏธ์ ์ ์ฅ์ | ||
| ### ๊ฒ์ ์ด๊ธฐํ | ||
|
|
||
| - [x] ๋ ํ๋ ์ด์ด๊ฐ ๊ฐ๊ฐ ์งํ์ ์ ํํ๋ค | ||
| - [x] ์งํ ์ ํ์ง: ์ผ์๋ง(๊ท๋ง), ์ค๋ฅธ์๋ง(๊ท๋ง), ์์๋ง, ์๊ท๋ง | ||
| - [x] ์ ํํ ์งํ์ ๋ฐ๋ผ ๋ง(้ฆฌ)์ ์(่ฑก)์ ์์น๊ฐ ๊ฒฐ์ ๋๋ค | ||
|
|
||
| ### ๊ธฐ๋ฌผ ์ด๋ | ||
|
|
||
| - [x] ์ฐจ(่ป): ์ง์ (๊ฐ๋ก/์ธ๋ก) ์ด๋, ์ด๋ ๊ฒฝ๋ก์ ๊ธฐ๋ฌผ์ด ์์ด์ผ ํ๋ค | ||
| - [x] ๋ง(้ฆฌ): ์ง์ 1์นธ + ๋๊ฐ์ 1์นธ ์ด๋, ์ฒซ ๋ฒ์งธ ์นธ์ ๊ธฐ๋ฌผ์ด ์์ด์ผ ํ๋ค | ||
| - [x] ์(่ฑก): ์ง์ 1์นธ + ๋๊ฐ์ 2์นธ ์ด๋, ์ด๋ ๊ฒฝ๋ก 2์นธ์ ๊ธฐ๋ฌผ์ด ์์ด์ผ ํ๋ค | ||
| - [x] ๊ถ(ๅฐ/ๅธฅ): ์ํ์ข์ฐ 1์นธ ์ด๋ | ||
| - [x] ์ฌ(ๅฃซ): ์ํ์ข์ฐ 1์นธ ์ด๋ | ||
| - [x] ํฌ(ๅ ): ์ง์ ์ด๋, ๋ฐ๋์ ๊ธฐ๋ฌผ 1๊ฐ๋ฅผ ๋ฐ์ด๋์ด์ผ ํ๋ฉฐ ํฌ๋ฅผ ๋๊ฑฐ๋ ํฌ๋ฅผ ์ก์ ์ ์๋ค | ||
| - [x] ๋ณ/์กธ(ๅ ต/ๅ): ์ ๋๋ ์ข์ฐ 1์นธ ์ด๋ | ||
|
|
||
| ### ์ด๋ ์ ํจ์ฑ ๊ฒ์ฆ | ||
|
|
||
| - [x] ์ด๋ ๋ถ๊ฐ๋ฅํ ์์น๋ก ์ด๋ ์ ์์ธ ์ฒ๋ฆฌ | ||
| - [x] ์ด๋ ๊ฒฝ๋ก ์ค๊ฐ์ ๊ธฐ๋ฌผ์ด ์์ ๊ฒฝ์ฐ ์ด๋ ๋ถ๊ฐ (ํฌ ์ ์ธ) | ||
| - [x] ์๊ตฐ ๊ธฐ๋ฌผ์ด ์๋ ์์น๋ก ์ด๋ ๋ถ๊ฐ | ||
| - [x] ์ ๊ตฐ ๊ธฐ๋ฌผ์ด ์๋ ์์น๋ก ์ด๋ ์ ํด๋น ๊ธฐ๋ฌผ ์ก๊ธฐ | ||
| - [x] ํฌ์ ๊ฒฝ์ฐ ์ด๋ ๊ฒฝ๋ก์ ์ ํํ 1๊ฐ์ ๊ธฐ๋ฌผ์ด ์์ด์ผ ์ด๋ ๊ฐ๋ฅ | ||
| - [x] ํฌ๋ ํฌ๋ฅผ ๋ฐ์ด๋๊ฑฐ๋ ํฌ๋ฅผ ์ก์ ์ ์๋ค | ||
|
|
||
| ### ๊ฒ์ ์งํ | ||
|
|
||
| - [x] ์ด(CHO)๊ฐ ๋จผ์ ์์ํ๊ณ ์ดํ ๋ฒ๊ฐ์ ์งํํ๋ค | ||
| - [x] ๋งค ํด ํ์ฌ ๋ณด๋ ์ํ๋ฅผ ์ถ๋ ฅํ๋ค | ||
| - [x] ์๋ชป๋ ์ ๋ ฅ ์ ์ฌ์ ๋ ฅ์ ๋ฐ๋๋ค | ||
|
|
||
| ### ์ถ๋ ฅ | ||
|
|
||
| - [x] 10x9 ๋ณด๋๋ฅผ ์ฝ์์ ์ถ๋ ฅํ๋ค | ||
| - [x] ์ด(CHO)๋ ํ๋์, ํ(HAN)์ ๋นจ๊ฐ์์ผ๋ก ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํ๋ค | ||
| - [x] ๋น ์นธ์ `ใ ก`๋ก ํ์ํ๋ค | ||
|
|
||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import controller.JanggiController; | ||
| import domain.piece.ConsolePieceAppearance; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class JanggiApplication { | ||
| public static void main(String[] args) { | ||
| JanggiController janggiController = new JanggiController(new InputView(), | ||
| new OutputView(new ConsolePieceAppearance())); | ||
| janggiController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package controller; | ||
|
|
||
| import domain.board.FormationType; | ||
|
|
||
| public final class FormationConverter { | ||
|
|
||
| private FormationConverter() {} | ||
|
|
||
| public static FormationType convert(int formationType) { | ||
| if (formationType == 1) return FormationType.LEFT_GIWMA; | ||
| if (formationType == 2) return FormationType.RIGHT_GIWMA; | ||
| if (formationType == 3) return FormationType.WONANGMA; | ||
| if (formationType == 4) return FormationType.YANGGWIMA; | ||
|
|
||
| throw new IllegalArgumentException("์ฌ๋ฐ๋ฅด์ง ์์ ์์ฐจ๋ฆผ ๋ฒํธ์ ๋๋ค."); | ||
| }; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package controller; | ||
|
|
||
| import domain.board.FormationType; | ||
| import domain.game.JanggiGame; | ||
| import domain.game.Team; | ||
| import domain.position.Position; | ||
| import java.util.List; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class JanggiController { | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| public JanggiController(InputView inputView, OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void run() { | ||
| JanggiGame game = createGame(); | ||
| outputView.printBoard(game.getBoard()); | ||
| while (game.isRunning()) { | ||
| playTurn(game); | ||
| } | ||
| } | ||
|
|
||
| private JanggiGame createGame() { | ||
| FormationType choFormation = FormationConverter.convert(inputView.initialFormation(Team.CHO)); | ||
| FormationType hanFormation = FormationConverter.convert(inputView.initialFormation(Team.HAN)); | ||
| return JanggiGame.of(choFormation, hanFormation); | ||
| } | ||
|
|
||
| private void playTurn(JanggiGame game) { | ||
| while (true) { | ||
| try { | ||
| List<Position> positions = inputView.askMovePiecePosition(game.currentTurn()); | ||
| game.move(positions.get(0), positions.get(1)); | ||
| outputView.printBoard(game.getBoard()); | ||
| return; | ||
| } catch (IllegalArgumentException e) { | ||
|
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. ์ปจํธ๋กค๋ฌ์์
Author
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. ๋ง๋ ๋ง์์ด์ ๊ฒ ๊ฐ์ต๋๋ค. ์ถ๋ ฅ ์ฑ
์์ด ์ปจํธ๋กค๋ฌ์ ์์๋ค์! |
||
| outputView.printError(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.game.Team; | ||
| import domain.piece.Piece; | ||
| import domain.piece.PieceType; | ||
| import domain.position.Position; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public abstract class AbstractBoardFactory implements BoardFactory { | ||
|
|
||
| private static final Map<FormationType, AbstractBoardFactory> factories = Map.of( | ||
| FormationType.LEFT_GIWMA, new LeftGwimaFactory(), | ||
| FormationType.RIGHT_GIWMA, new RightGwimaFactory(), | ||
| FormationType.WONANGMA, new WonangmaFactory(), | ||
| FormationType.YANGGWIMA, new YanggwimaFactory() | ||
| ); | ||
|
|
||
| public static AbstractBoardFactory from(FormationType type) { | ||
| AbstractBoardFactory factory = factories.get(type); | ||
| if (factory == null) { | ||
| throw new IllegalStateException("ํด๋น ํ์ ์ ํฉํ ๋ฆฌ๊ฐ ๋ฑ๋ก๋์ง ์์์ต๋๋ค."); | ||
| } | ||
| return factory; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<Position, Piece> createFormation(Team team) { | ||
| Map<Position, Piece> pieces = new HashMap<>(); | ||
| setFixedPieces(pieces, team); | ||
| setVariablePieces(pieces, team); | ||
| return pieces; | ||
| } | ||
|
|
||
| private void setFixedPieces(Map<Position, Piece> pieces, Team team) { | ||
| placePieces(pieces, team, team.getBackRow(), PieceType.CHA); | ||
| placePieces(pieces, team, team.getBackRow(), PieceType.SA); | ||
| placePieces(pieces, team, team.getGeneralRow(), PieceType.GENERAL); | ||
| placePieces(pieces, team, team.getCannonRow(), PieceType.PHO); | ||
| placePieces(pieces, team, team.getSoldierRow(), PieceType.BYEONG); | ||
| } | ||
|
|
||
| private void placePieces(Map<Position, Piece> pieces, Team team, int row, PieceType type) { | ||
| for (int column : type.getInitialColumns()) { | ||
| pieces.put(new Position(row, column), type.createPiece(team)); | ||
| } | ||
| } | ||
|
|
||
| protected abstract void setVariablePieces(Map<Position, Piece> pieces, Team team); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.piece.EmptyPiece; | ||
| import domain.piece.Piece; | ||
| import domain.position.Position; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Board { | ||
| private final Map<Position, Piece> pieces; | ||
|
|
||
| public Board(Map<Position, Piece> pieces) { | ||
| this.pieces = new HashMap<>(pieces); | ||
| } | ||
|
|
||
| public void move(Position source, Position destination) { | ||
| Piece piece = pieceAt(source); | ||
| validateCanMove(piece, source, destination); | ||
| List<Position> route = piece.calculateRoute(source, destination); | ||
| List<Piece> piecesOnRoute = route.stream() | ||
| .map(this::pieceAt) | ||
| .collect(Collectors.toList()); | ||
| piece.validateRoute(piecesOnRoute, pieceAt(destination)); | ||
| applyMove(source, destination, piece); | ||
| } | ||
|
|
||
| private void validateCanMove(Piece piece, Position source, Position destination) { | ||
| if (!piece.canMove(source, destination)) { | ||
| throw new IllegalArgumentException("์ด๋ํ ์ ์๋ ์์น์ ๋๋ค."); | ||
| } | ||
| } | ||
|
|
||
| private void applyMove(Position source, Position destination, Piece piece) { | ||
| pieces.put(destination, piece); | ||
| pieces.put(source, EmptyPiece.getInstance()); | ||
| } | ||
|
|
||
| public Piece pieceAt(Position position) { | ||
| return pieces.getOrDefault(position, EmptyPiece.getInstance()); | ||
| } | ||
|
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.
Author
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. ์์ ๋งํด์ฃผ์ ์ฑ๊ธํค ๊ฐ์ฒด์ ๋ํด์ ์์๋ดค์ต๋๋ค. ํ์คํ ๊ธฐ์กด ์ ์ฝ๋์์๋ ํญ์ ์๋ก์ด EmptyPiece๊ฐ ์์ฑ๋๊ณ ์์๊ณ ์ด๋ก์ธํด ๋ถํ์ํ ๋ฆฌ์์ค ๋ญ๋น๊ฐ ์ผ์ด๋๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. EmptyPiece์ ์ฑ๊ธํค์ ์ ์ฉํ๊ฒ ๋๋ฉด ํด๋น ์ธ์คํด์ค๋ ๋ฐํ์ ๋์ ๋จ ํ๋์ ์ธ์คํด์ค๋ง ์์ฑ๋๊ณ getInstance()๋ฅผ ํตํด ํ์ํ ๋๋ง๋ค ํธ์ถํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌ์ฑ๋์ด ๋์ฑ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.position.Position; | ||
| import domain.piece.Piece; | ||
| import domain.game.Team; | ||
| import java.util.Map; | ||
|
|
||
| public interface BoardFactory { | ||
| Map<Position, Piece> createFormation(Team team); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package domain.board; | ||
|
|
||
| public enum FormationType { | ||
| LEFT_GIWMA, | ||
| RIGHT_GIWMA, | ||
| WONANGMA, | ||
| YANGGWIMA | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.position.Position; | ||
| import domain.piece.Piece; | ||
| import domain.piece.PieceType; | ||
| import domain.game.Team; | ||
| import java.util.Map; | ||
|
|
||
| public class LeftGwimaFactory extends AbstractBoardFactory { | ||
| @Override | ||
| protected void setVariablePieces(Map<Position, Piece> pieces, Team team) { | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(0)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(1)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(2)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(3)), | ||
| PieceType.MA.createPiece(team)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.position.Position; | ||
| import domain.piece.Piece; | ||
| import domain.piece.PieceType; | ||
| import domain.game.Team; | ||
| import java.util.Map; | ||
|
|
||
| public class RightGwimaFactory extends AbstractBoardFactory { | ||
| @Override | ||
| protected void setVariablePieces(Map<Position, Piece> pieces, Team team) { | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(0)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(1)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(2)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(3)), | ||
| PieceType.SANG.createPiece(team)); | ||
| } | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.position.Position; | ||
| import domain.piece.Piece; | ||
| import domain.piece.PieceType; | ||
| import domain.game.Team; | ||
| import java.util.Map; | ||
|
|
||
| public class WonangmaFactory extends AbstractBoardFactory { | ||
| @Override | ||
| protected void setVariablePieces(Map<Position, Piece> pieces, Team team) { | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(0)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(1)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(2)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(3)), | ||
| PieceType.SANG.createPiece(team)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.position.Position; | ||
| import domain.piece.Piece; | ||
| import domain.piece.PieceType; | ||
| import domain.game.Team; | ||
| import java.util.Map; | ||
|
|
||
| public class YanggwimaFactory extends AbstractBoardFactory { | ||
| @Override | ||
| protected void setVariablePieces(Map<Position, Piece> pieces, Team team) { | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(0)), | ||
| PieceType.MA.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(1)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.SANG.getInitialColumns().get(2)), | ||
| PieceType.SANG.createPiece(team)); | ||
| pieces.put(new Position(team.getBackRow(), PieceType.MA.getInitialColumns().get(3)), | ||
| PieceType.MA.createPiece(team)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package domain.game; | ||
|
|
||
| import domain.board.AbstractBoardFactory; | ||
| import domain.board.Board; | ||
| import domain.board.FormationType; | ||
| import domain.piece.Piece; | ||
| import domain.position.Position; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class JanggiGame { | ||
| private Turn turn; | ||
| private final Board board; | ||
|
|
||
| public JanggiGame(Turn turn, Board board) { | ||
| this.turn = turn; | ||
| this.board = board; | ||
| } | ||
|
|
||
| public static JanggiGame of(FormationType choFormation, FormationType hanFormation) { | ||
| Map<Position, Piece> pieces = new HashMap<>(); | ||
| pieces.putAll(AbstractBoardFactory.from(choFormation) | ||
| .createFormation(Team.CHO)); | ||
| pieces.putAll(AbstractBoardFactory.from(hanFormation) | ||
| .createFormation(Team.HAN)); | ||
| return new JanggiGame(Turn.first(),new Board(pieces)); | ||
| } | ||
|
|
||
| public void move(Position source, Position destination) { | ||
| board.move(source, destination); | ||
|
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.
|
||
| turn = turn.next(); | ||
| } | ||
|
|
||
| public boolean isRunning() { | ||
| return true; // TODO: ์ข ๋ฃ ์กฐ๊ฑด ๊ตฌํ | ||
| } | ||
|
|
||
| public Team currentTurn() { | ||
| return turn.current(); | ||
| } | ||
|
|
||
| public Board getBoard() { | ||
| return board; | ||
| } | ||
| } | ||
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.
์ง๋ฌธ์ธ๋ฐ์. controller๋ ์ด๋์ ์ฐฉ์ํ์ ๋ค์ด๋ฐ์ผ๊น์? ์ controller์ธ๊ฐ์?
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.
์ด๋ฒ์ ๋น๋ฐฅ์ด ์ง๋ฌธํด์ฃผ์ ๋๋ถ์ ์ปจํธ๋กค๋ฌ๊ฐ ์ด๋ค ์ญํ ์ ๊ฐ์ ธ์ผ ํ๋์ง์ ๋ํด ๋ค์ ์ ๋ฆฌํด๋ณด์์ต๋๋ค.
์๋ฃ๋ฅผ ์ฐพ์๋ณด๋ ๊ณผ์ ์์ ๊ธ๋ง๋ค ์ค๋ช ์ด ์กฐ๊ธ์ฉ ๋ฌ๋ผ์ ๊ธฐ์ค์ ์ก๋ ๋ฐ ์๊ฐ๋ณด๋ค ์ด๋ ค์์ ๋๊ผ๊ณ , ๊ทธ๋์ ๋๋ฆ๋๋ก ๊ธฐ์ค์ ์ธ์ ์ ๋ฆฌํด๋ดค์ต๋๋ค.
์ฐ์ ์ปจํธ๋กค๋ฌ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ง์ ์ ์ด์ ํ๋ฆ์ ์ ์ดํ๋ ์ญํ ์ด๋ผ๊ณ ์ดํดํ์ต๋๋ค. ์ธ๋ถ(View, ํด๋ผ์ด์ธํธ)์ ๋ด๋ถ(Model, Service) ์ฌ์ด์์ ์ค๊ฐ ๋ค๋ฆฌ ์ญํ ์ ํ๋ฉด์, ์ ๋ ฅ์ ๋๋ฉ์ธ์ด ์ดํดํ ์ ์๋ ํํ๋ก ๋ณํํ๊ณ , ๋ฐ๋๋ก ๊ฒฐ๊ณผ๋ฅผ ์ธ๋ถ์ ๋ง๊ฒ ๋ณํํ๋ โ๋ฒ์ญ๊ฐโ ์ญํ ์ ํ๋ค๊ณ ์๊ฐํ์ต๋๋ค. ๋ํ ์๋ชป๋ ์์ฒญ์ ์ด๊ธฐ์ ๊ฑธ๋ฌ๋ด๊ณ ํ๋ฆ์ ์ ์ดํ๋ โ๋ฌธ์ง๊ธฐโ ์ญํ ๋ ํจ๊ป ๊ฐ์ง๋ค๊ณ ์ ๋ฆฌํ์ต๋๋ค.
์๋น์ค ๋ ์ด์ด์ ์ ๋ฌด์ ๋ฐ๋ผ์๋ ์ญํ ์ ๋ฌด๊ฒ๊ฐ ๋ฌ๋ผ์ง๋ค๊ณ ๋ณด์์ต๋๋ค. ์๋น์ค๊ฐ ์๋ ๊ตฌ์กฐ์์๋ ์ปจํธ๋กค๋ฌ๊ฐ ๋๋ฉ์ธ ๊ฐ์ฒด๋ค์ ์ง์ ์กฐํฉํ๋ฉด์ ํ๋ฆ์ ์ด๋๋ ์ญํ ๊น์ง ๋ด๋นํ๊ฒ ๋๊ณ , ์๋น์ค ๋ ์ด์ด๊ฐ ์๋ ๊ฒฝ์ฐ์๋ ๊ทธ ์ฑ ์์ ์๋น์ค์ ์์ํ๊ณ ์ปจํธ๋กค๋ฌ๋ ๋ผ์ฐํ ์ ์ง์คํ๋ ๊ตฌ์กฐ๊ฐ ๋ ์ ์ ํ๋ค๊ณ ์ดํดํ์ต๋๋ค.
๋ ํ๋ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์, ์ปจํธ๋กค๋ฌ๊ฐ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ View๋ก ์ด๋ป๊ฒ ์ ๋ฌํด์ผ ํ๋์ง์์ต๋๋ค. ๋๋ฉ์ธ ๋ชจ๋ธ์ ๊ทธ๋๋ก ๋๊ธฐ๋ ๋ฐฉ์์ View๊ฐ ๋๋ฉ์ธ ๋ด๋ถ๋ฅผ ์๊ฒ ๋๋ฉด์ ๊ฒฐํฉ๋๊ฐ ๋์์ง๋ค๊ณ ๋๊ผ๊ณ , ์ด๋ฅผ ํผํ๊ธฐ ์ํด DTO๋ก ๋ณํํด์ ์ ๋ฌํ๋ ๋ฐฉ์์ด ๋ ์ ์ ํ๋ค๊ณ ํ๋จํ์ต๋๋ค. DTO๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ฉ์ธ์ ๋ณดํธํ ์ ์๊ณ , View์์ ์์กด์ฑ๋ ๋์ ์ ์์ด์ ๋ณ๊ฒฝ์ ๋ ์ ์ฐํ๊ฒ ๋์ํ ์ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
์ด๋ ๊ฒ ๋๋ฆ๋๋ก ๊ธฐ์ค์ ์ธ์ ์ ๋ฆฌํด๋ณด์๋๋ฐ, ํน์ ์ ๊ฐ ๋์น๊ณ ์๊ฑฐ๋ ์๋ชป ์ดํดํ ๋ถ๋ถ์ด ์๋ค๋ฉด ๋น๋ฐฅ์ ์๊ฒฌ์ ๋ค์ด๋ณด๊ณ ์ถ์ต๋๋ค.
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.
์ ์ ๋ ์ง๊ธ controller์ ๋ํด ๊ต์ก์ ๋ฐ์๊ฑด๊ฐ ํด์ ์ฌ์ญค๋ณธ๊ฑฐ์๋๋ฐ์
์ง๊ธ์ ์ด ๋ถ๋ถ๋ณด๋ค ๋ค๋ฅธ ๋ถ๋ถ์ ์ง์คํ์๋๊ฒ ๋ ๋ซ์ง ์๋ ์ถ์ต๋๋ค.
์ฐพ์๋ณด์ ๋ด์ฉ๋ค์ ์ ์ ๋ฆฌํด์ ๊ณ์ํด์ ๋ฐ์ ์ํค๋ฉด ์ข์๊ฒ ๊ฐ์ต๋๋ค. ๐