-
Notifications
You must be signed in to change notification settings - Fork 53
[ 사다리 - 함수형 프로그래밍 ] 박채연 미션 제출합니다. #57
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: qkrcodus
Are you sure you want to change the base?
Conversation
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.
채연님 도메인 파악부터 시작해야해서 미션이 까다로웠을텐데 잘 구현해주셨네요!
객체별 역할을 구분하는 연습을 하시는 모습 좋습니다👍
현재 어플리케이션을 수행해보면 IndexOutOfBoundsException이 발행하는데요.
이부분 수정 부탁드리며, 테스트 코드도 작성하면서 기능이 잘 구현되었는지 그때 그때 검증해보며 진해앻보면 좋을 것 같습니다! 홧팅🔥
public class Ladder { | ||
private List<Floor> floors; |
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.
사다리는 N개의 층을 가질 수 있고, 층은 N개의 연결여부를 가지고 있게 구성해주셨군요! 좋습니다😎
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.
List는 변경될 수 없음을 보장하기 위해서는 어떻게 해야할까요?
public Ladder(int height, int width, Random random) { | ||
this.floors = generateFloors(height, width, random); | ||
} | ||
|
||
private List<Floor> generateFloors(int height, int width, Random random) { | ||
List<Floor> floors = new ArrayList<>(); | ||
for (int i = 0; i < height; i++) { | ||
floors.add(new Floor(width, random)); | ||
} | ||
return floors; | ||
} |
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.
List floors를 넣어주는 생성자를 만들어주고, 높이와 넓이 connection 생성전략을 넣어주는 정적 팩토리메서드를 만들어주면 어떨까요?
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.
높이와 넓이에 대한 검증도 있으면 좋겠네요!
public Floor(int width,Random random) { | ||
connections = new ArrayList<>(); | ||
boolean previousConnection = false; | ||
for (int i = 0; i < width-1; i++) { | ||
Connection connection =Connection.of(previousConnection,random); | ||
connections.add(connection); | ||
previousConnection = connection.isConnected(); | ||
} | ||
} |
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.
List를 넣어주는 생성자를 만들어주고, 넓이와 connection 생성전략을 넣어주는 정적 팩토리메서드를 만들어주면 어떨까요?
생성자에서는 어떤것을 검증해볼 수 있을까요? (Floor가 어떤 규칙을 가져야하는지 생각해보면?)
public class Connection { | ||
private final boolean connected; | ||
|
||
private Connection(boolean connected) { | ||
this.connected = connected; | ||
} | ||
|
||
public static Connection of(boolean previousConnected, Random random) { | ||
boolean connect = !previousConnected && random.nextBoolean(); | ||
return new Connection(connect); | ||
} |
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.
이건 선택의 영역이지만 Floor 내의 커낵션을 결정하는 로직은 Floor가 가지고 있어도 무방하다고 생각하긴 합니다!
그래도 값들을 최대한 값객체로 만들어보려는 시도 좋습니다👍
public void printResult(LadderResult result, int width) { | ||
for (int i = 0; i < width; i++) { | ||
int end = result.move(i); | ||
System.out.println(i + " -> " + end); | ||
} | ||
} |
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.
누구의 역할일까요?
public class LadderResult { | ||
private final Ladder ladder; |
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.
LadderResult라는 이름을 가지고 있지만, Ladder 내에서의 움직임 정책을 담당하고 있는 것 같아요.
움직임을 수행시키고 결과를 만들어 반환하는 객체로 바꿔보면 좋을 것 같고, LadderResult는 정말 결과만 들고 있으면 좋을 것 같네요!
} | ||
|
||
private int movePosition(Floor floor, int index) { | ||
if (floor.getConnections().get(index).isConnected()) { |
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.
floor에게 물어볼 수 있지 않을까요?
[ enum ] - 고정된 상태에 따른 행동/속성 정의하고 싶을 때 사용
[ 일급 컬렉션 ] - 컬렉션이 도메인 의미 갖고 있을 때 사용
Enum 과 일급 컬렉션은 둘 다 정보 은닉을 목적으로 한다.
[ 원시값 포장 ] - 원시값이 도메인 의미 갖고 있을 때 사용
사다리 구성요소가 무엇인지 생각하며 어떤 클래스들이 필요할지 고민했습니다.
Ladder -> Floor -> Connection
Ladder : List < Floor > - 일급 컬렉션
Floor : List < Connection > - 일급 컬렉션
Connection : boolean isConnected, public static Connection.of(boolean) - 정적 팩토리 메서드 (생성 제약 있음)
원시값 포장이 필요한 부분은 없는 것 같다.
3단계 게임 결과 출력하기
정리