Skip to content
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

1주차 미션/ 서버 1조 박지원 #4

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

david-parkk
Copy link
Member

안녕하세요 서버 1조 박지원(david-parkk)입니다.
설계의 중요성을 망각하고 항상 코드를 막쓰는 것이 습관화되어 객체지향적으로 개발하는데 많은 어려움이 있었습니다.
제 바람과 달리 스파게티 코드가 만들어져 코드리뷰하시는 파트장님께 미리 사과 드리겠습니다. 😢
제가 중점적으로 생각하고 진행한 내용에 대해 설명드리겠습니다.

1. 매직 넘버, 리터럴 관리

  • 가장 먼저 눈에 띄었던 것은 몇가지 매직 넘버와 매직 리터럴(거이 다 Error message)이 였습니다.
  • util package PipeConstant 클래스 ErrorCode, CustomException 클래스를 정의하여 별도로 관리하였습니다.
  • 적어도 의미가 있는 상수들은 최대한 관리하고자 하였고, 의미가 없거나 관리할 필요없이 너무 의미가 명백한 경우는 관리대상에서 제외 시켰습니다.

2. 원시값 포장

  • 사다리게임에서 관리되고 있던 int [] rows; 을 int 형에서 Pipe 클래스로 대체하였습니다.
  • Pipe 클래스는 각각 어떤 다리와 연결되어있는지 상태만 가지게 됩니다

3. 인터페이스화

  • Game,Field 인터페이스를 통해 각각 Laddergame 와 Ladder 을 구현체로 가져가도록 하였습니다.
  • 추상화를 하고 이를 테스트에 적용하는게 목표였는데 원하는 대로 구현되지 않은 것 같습니다

4. 패키지화

  • field, fieldComponent, component 패키지를 통해 사다리 게임의 구성요소를 분리하였습니다.
  • 해당 요소에 알맞는 기타 클래스는 util 패키지로 관리합니다.

5. 정적 팩터리 메소드

  • 객체생성 역활을 팩터리 메소드에게 맡기도록 구현하였습니다.

구현하면서 가장 크게 느낀점으로는 단순히 리펙토링을 하는 것보다 기능을 추가하면서 리펙토링하는 것이 더 좋은 작업 능률을 가졌다는 점과 객체지향개발이 정말 어렵다는 것을 느꼈습니다

@david-parkk david-parkk changed the title David parkk 1주차 미션/ 서버 1조 박지원 Mar 20, 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.

미션 하시느라 정말 고생 많으셨습니다!
객체지향을 고려하여 설계하고 코드를 작성하는 부분은 정답이 없어 제 코드 리뷰가 도움이 되셨으면 좋겠습니다.
구현해주신 부분 안에서 최대한 보완하면 좋은 점을 적어봤습니다! 코드 작성하시느라 정말 고생하셨고 객체지향 적으로 코드를 짜려는 노력이 돋보입니다!!

Comment on lines +5 to +9
public static final int LEFT_DRAW_CONSTANT = -1;
public static final int RIGHT_DRAW_CONSTANT = 1;
public static final int NOTHING = 0;
public static final int COL_BLOCK_SIZE = 1;
public static final int START_INDEX = 0;

Choose a reason for hiding this comment

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

final 상수를 통해 상수도 관리하는 것도 좋지만, 가독성이 떨어지는 장점이 있는것 같아요!
final 상수 대신 코드가 단순해지고, 가독성이 좋은 enum 클래스를 사용해보는 것은 어떨까요?

package game.component.util;

public enum PipeStatus {
Left(PipeConstant.LEFT_DRAW_CONSTANT), Right(PipeConstant.RIGHT_DRAW_CONSTANT), Nothing(PipeConstant.NOTHING);

Choose a reason for hiding this comment

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

PipeStatus 에서 LEFT_DRAW_CONSTANT, RIGHT_DRAW_CONSTANT, NOTHING 상수를 선언해서 관리하는 것이 나을것 같아요!

Comment on lines +3 to +14
public class CustomException extends RuntimeException {
private final ErrorCode errorCode;

public CustomException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}

public ErrorCode getErrorCode() {
return errorCode;
}
}

Choose a reason for hiding this comment

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

커스텀 예외까지 직접 만드시는 것도 정말 좋네요!

Comment on lines +47 to +48
validateBallPosition(position[0],position[1]);
ball.initializePosition(position[0],position[1]);

Choose a reason for hiding this comment

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

validateBallPosition, initializePosition 메서드가 runWithPrint 에서 중복되는 것 같아요! 따로 이 부분을 private 메서드로 빼는 것도 좋을 것 같습니다.

}
}
private void validateBallPosition(int row,int col){
if(row<0||row>=rows.length)

Choose a reason for hiding this comment

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

if 문안에 row<0|| row>=rows.length를 따로 private 메서드로 빼서 이름을 지정하면, 더 가독성이 좋을 것 같아요!

Comment on lines +5 to +6
private int row;
private int col;

Choose a reason for hiding this comment

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

rowcol 필드가 1 이상인 정수 조건을 가져야 하므로 예외 처리 메서드도 필요할 것 같네요!

Comment on lines +7 to +11
private PipeStatus pipeStatus;

public Pipe(){
this.pipeStatus=PipeStatus.Nothing;
}

Choose a reason for hiding this comment

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

정적 팩터리 메서드 패턴을 사용해보는 것이 어떨까요?

rows[i] = new Row(numberOfPerson);
}
}
public Ladder(int numberOfRows, int numberOfPerson,int randomCount) {

Choose a reason for hiding this comment

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

메서드의 이름을 Ladder 보다 랜덤 카운트를 받는다는 의미를 가진 이름으로 설정하는게 나아보여요! LadderWithRandom 이런 식으로요!


public class LadderConstant {

public static final int ROW_BLOCK_SIZE = 1;

Choose a reason for hiding this comment

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

상수가 하나뿐이라, 단순히 클래스로 빼는것보다 Ladder 클래스에서 선언하는것도 좋을 것 같아요!

Comment on lines +36 to +41
try {
validateDrawLinePosition(position);
}
catch(Exception e){
return false;
}

Choose a reason for hiding this comment

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

try-with-resources 를 활용해 처리하는것이 좋네요!

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