Skip to content

Conversation

@chaewon121
Copy link

@chaewon121 chaewon121 commented Mar 27, 2023

로운 안녕하세요! 채채 입니다. 이번 단계 리뷰도 잘부탁드립니다!

@chaewon121 chaewon121 changed the title Step2 [3, 4단계 - 체스] 채채(신채원) 미션제출합니다 Mar 27, 2023
@chaewon121 chaewon121 changed the base branch from main to chaewon121 March 27, 2023 07:35
Copy link

@lowoon lowoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 채채!😄
이제 그만 체스 미션을 마무리해도 될 것 같아요.
간단한 코멘트만 남겼으니 확인 부탁드려요.
미션은 끝났지만 궁금한점 있으면 DM이나 코멘트로 남겨주세요!

1 ~ 4단계 체스 미션 수고하셨습니다!

@@ -0,0 +1,17 @@
CREATE TABLE piece
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

참고만 하시면 될 것 같아요~
piece와 board라고 해서 piece와 위치를 분리해서 관리할 수도 있을 것 같아요~

private final PieceDao pieceDao;
private final GameDao gameDao;

public ChessGame() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

비지니스 로직을 담당하는 game에서 dao 관리 👍
다음에는 내부에서 생성하는 것이 아닌 parameter로 넘겨받는 방식을 생각해보면 좋을것 같아요!
관련해서 의존성 주입에 대해서 학습하면 좋을 것 같습니다~

private static final String USERNAME = "root"; // MySQL 서버 아이디
private static final String PASSWORD = "root"; // MySQL 서버 비밀번호

public Connection getConnection() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection은 공통이기 때문에 따로 빼도 될것 같구요!
지금은 jdbc이지만 jpa등 다른 방식을 사용할 수도 있다는 점을 고민해보면 좋을 것 같아요!

}
}

public void updateByTurn(final int gameId, final String state) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move할때마다 저장이 되는데요. 2가지 방식이 있을거에요

  1. 움직일때마다 db에 저장
  2. end를 했을 때 저장 (이 경우 중간에 에러가 발생했을 때는 어떻게 할지 고민이 필요)
    각각의 방식의 장단점이 있고, 요구사항에 따라 달라질 수 있는 부분인데요.
    이러한 방법도 있구나라고 생각만하시면 될것 같습니다~

}
}

public void addPiece(final PieceEntity boardTable) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save라는 명으로 사용하는 것 같구요
for문을 돌며 piece를 하나씩 intsert하고 있는데요.
이렇게 하면 insert구문이 많이 호출되어 db에 부하가 가해질 수 있습니다.
bulk로 한번에 여러개를 insert하는 걸 찾아보면 좋을것 같아요!
jdbcTemplate의 batchUpdate preparedStatement의 addBatch을 참고하시면 좋을것 같아요~

}
}

public Piece findByPosition(final Position position) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 position을 모두 순회하면서 piece를 찾는데요.
이러한 방식보다 한번에 같은 gameId를 가진 piece들을 한번에 가지고 오고 이 piece들을 위치에 맞게 board로 만드는 방식이 더 효율적이지 않을까요??


public class GameEntity {
private final int gameId;
private final String turn;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2가지 방법이 있을텐데요.

  1. 도메인처럼 enum
  2. 객체를 가지는 방법 혹은 원시값 형태로만 가지는 방법

어떠한 방법이 좋을까요?? entity와 도메인은 무엇이 다른걸까요??
이러한 부분에 대해서 고민해보시면 좋을것 같습니다!
그리고 entity를 만들었다면 dao를 통해 find해서 나온 객체 또한 entity여야하지 않을까요??

private final GameDao gameDao = new GameDao();

@Test
public void connection() throws SQLException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db 테스트의 경우 복잡한 쿼리가 아닌 경우에는 대부분 실제 db에 연동하여 테스트를 진행하지는 않는 것 같아요!
말씀하신 것처럼 mock을 사용하여 테스트하는 것 같아요. ChessGame 테스트에서 mock dao를 주입하여 테스트할 수 있겠죠?
하지만 jdbc의 경우에는 직업 쿼리에 동작하는 부분을 모두 설정해주기 때문에 테스트가 필요하다고 생각합니다.
jpa와 같은 orm의 경우에는 쿼리만 작성하고 mapping은 내부적으로 해주는 것이라 처음에 말한 방식으로 테스트하지만 jdbc는 다르다고 생각합니다.
이렇게 어떠한 library, 프레임워크를 쓰느냐에 따라서도 테스트를 작성하는 방식이 달라질 수 있을거에요.
이러한 부분을 참고하여 테스트를 어떠한 기준을 작성할지 고민하고 채채만의 기준을 만들어나가면 좋을것 같습니다!

public void addTurn(final GameEntity gameEntity) {
final var query = "INSERT INTO game VALUES(?, ?)";
try (final var connection = getConnection();
final var preparedStatement = connection.prepareStatement(query)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var로 정의한 이유가 있나요??


CREATE TABLE game
(
game_id INT NOT NULL,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key는 보통 bigint를 사용하고 java에서는 long으로 사용하는 것 같아요!

@lowoon lowoon merged commit 441095c into woowacourse:chaewon121 Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants