Skip to content

Conversation

@yuna569
Copy link

@yuna569 yuna569 commented Sep 27, 2024

기능 구현은 완료하였으나 리팩토링이 더 필요할 것 같습니다. 추가적으로 진행해보겠습니다!

Copy link

@kmw10693 kmw10693 left a comment

Choose a reason for hiding this comment

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

코드 짜느라 고생하셨어요 ㅎㅎ!
객체지향적으로 코드를 짜보려고 노력해보신 모습이 보여 인상 깊습니다!
2주차 미션 하느라 고생하셨습니다!

Comment on lines +2 to +3
private LadderCreator ladderCreator;
private RunGame runGame;

Choose a reason for hiding this comment

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

클래스를 final로 선언해서 불변 객체로 만들면 어떨까요?

Comment on lines +18 to +24
LadderCreator ladderCreator = new LadderCreator(Index.from(5), Index.from(7), false);

PositionOfLine position = PositionOfLine.of(Index.from(3), Index.from(2));

ladderCreator.drawLine(position);

Assertions.assertThat(ladderCreator.LineAlreadyExisting(position.getX(), position.getY())).isEqualTo(true);

Choose a reason for hiding this comment

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

테스트 코드를 잘 작성해주셨네요! 테스트 코드 작성에 있어, BDD(given when then)방식으로 테스트를 해볼수 있습니다! 한번 BDD 에 대해 알아보세요!

@@ -0,0 +1,19 @@
public class LadderGameFactory {

Choose a reason for hiding this comment

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

객체지향을 살릴 수 있는 디자인 패턴중 팩터리 메서드 패턴이란 것이 있습니다!
팩터리 메서드 패턴은 클래스의 인스턴스 생성을 서브 클래스에게 맡기는 것인데요!
지금 이 코드는 메서드가 겹쳐 코드의 중복도가 높은 것 같습니다.

  1. LadderGameFactory를 추상 클래스(abstract class)로 선언합니다.
  2. 추상 클래스 내에 공통으로 게임을 만드는 createGame() 메서드를 선언합니다.
  3. createLadderGame 클래스와 createRandomLadderGame 클래스는 1번 추상 메서드를 확장하여 각각의 인스턴스를 반환합니다.
  4. 구상 클래스(createLadderGame, createRandomLadderGame) 클래스의 createGame() 메서드를 통해 객체를 반환받습니다.

이런식으로 하면 코드를 확장할때도, 객체지향적으로 용이해보이네요!
디자인 패턴 중 팩터리 메서드 패턴에 대해 공부해보시면 좋을 것 같아요!

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