Conversation
javajigi
left a comment
There was a problem hiding this comment.
볼링 구현이 쉽지 않을텐데 구현하느라 고생했네요. Frame의 현재 상태(strike, spare, miss 등의 여부)를 Frame을 통해 알 수 있도록 구현하면 어떨까요?
| public class BowlingGameConsoleApp { | ||
| public static void main(String[] args) { | ||
| String playerName = InputView.showGetPlayerNameView(); | ||
| LinkedList<Frame> frames = new LinkedList<>(); |
There was a problem hiding this comment.
List frames = new LinkedList<>();
위와 같이 List로 구현 가능.
ArrayList를 사용하지 않고 LinkedList를 사용해 구현한 이유는?
There was a problem hiding this comment.
List frames = new LinkedList<>();와 같이 List로 구현이 가능하지만 frames.getLast()를 사용할 수 없어 직접 LinkedList를 명시하여 구현하였습니다. 구현방법은 얼마든지 변경할 수 있는 부분이라 현재 List로 구현을 시도하고 있습니다.- ArrayList를 사용하지 않고 LinkedList를 사용해 구현한 이유는
2단계(점수 계산)를 일부러 미리 준비했다기보단 1단계에 명시된 구현 방법점수 계산 방식을 모르는 사람은 구글에서 "볼링 점수 계산법"과 같은 키워드로 검색해 볼링 게임의 점수 계산 방식을 학습한 후 구현을 시작한다.에 따라 점수 계산법을 익혔고 이것을 구현 중 고려해야 하는 사항으로 포함하였기 때문입니다.
There was a problem hiding this comment.
Frame을 ArrayList로 관리하나 LinkedList로 구현하나 특별히 차이점은 없을 것 같아요?
제가 봤을 때 LinkedList를 고려한 이유는 Frame이 다음 Frame에 접근해야 하는 경우가 발생할 수 있기 때문이라고 생각하는데요. 그런 구조를 고려했다면 Frame 자체가 nextFrame을 인스턴스 변수로 가짐으로써 Frame이 LikedList와 같은 자료구조 형태를 가질 때 의미가 있다고 봅니다.
There was a problem hiding this comment.
네, 맞습니다! 다음 Frame에 접근할 것을 고려하였기 때문인데, 강사님의 말씀을 듣고 생각해보니..... 제가 착각한 부분이 있는 것 같습니다. Frame 내부에서 다음 Frame에 접근할 것을 고려해놓고, 반대로 또다시 Frame 외부에서 LinkedList로 다음 Frame 접근을 고려하는 것은 이상한 구조로 보입니다. 다시 구현해보겠습니다.
| Pitch secondPitch; | ||
| public static final int DEFAULT_START_PIN_COUNT = 10; | ||
| public static final int MIN_FRAME_NUMBER = 1; | ||
| public static final int MAX_FRAME_NUMBER = 10; |
There was a problem hiding this comment.
클래스의 구현 순서는 다음과 같다. 다음 원칙에 따라 구현한다.
class A {
상수(static final) 또는 클래스 변수
인스턴스 변수
생성자
메소드
}
| public abstract class Frame { | ||
| int frameNumber; | ||
| Pitch firstPitch; | ||
| Pitch secondPitch; |
There was a problem hiding this comment.
인스턴스 변수는 특별한 이유는 없는 한 private으로 구현한다.
객체 외부에서 상태 값을 임의로 변경할 수 있도록 하는 것은 캡슐화 위반이다.
자식에서 접근이 필요하더라도 private으로 구현하고, 접근이 필요한 경우 method를 통해 접근한다.
There was a problem hiding this comment.
- private로 구현하고 get메서드를 통해 접근할 수 있도록 변경하였습니다.
- set메서드도 필요하여 protected 접근제어자를 붙여 구현하였습니다. set함수를 되도록이면 만들지 않는 것이 좋다고 하셨지만 지금 구조에서는 부득이하게 필요한데 어떻게 생각하시나요?
There was a problem hiding this comment.
@ssosso
현재 frame의 상태를 변경하는 메소드는 bowl이 있는데요. set 메소드를 추가하지 않고 bowl 메소드를 활용할 수 있지 않을까요? bowl() 메소드가 부모인 Frame에 있고, 10 Frame의 경우 예외케이스가 있으니 이 bowl 메소드를 override하는 구조로 구현하면 혹시 가능하지 않을까요?
| public class FinalFrame extends Frame { | ||
| private Pitch thirdPitch; | ||
|
|
||
| public FinalFrame(int frameNumber, int firstPitch) { |
There was a problem hiding this comment.
FinalFrame의 frameNumber는 당연히 10인데 굳이 생성자의 인자로 받아야 하나?
|
|
||
| public abstract Frame bowl(int pinCount); | ||
|
|
||
| public abstract boolean isComplete(); |
There was a problem hiding this comment.
Frame의 상태를 반환하는 다양한 메소드를 통해 외부에서 ResultType을 결정하는 것이 아니라..
Frame 자체가 ResultType을 결정하는 것이 어떨까?
public ResultType getStatus() {
}
위와 같은 메소드를 Frame이 가진다면..?
src/main/java/view/OutputView.java
Outdated
| String displayValue = String.format(ResultType.resultOf(frame).getDisplayFormat(), pitches.stream() | ||
| .map(pitch -> pitch == null ? "" : pitch.getPinCount()) | ||
| .toArray()); | ||
| if(frame instanceof FinalFrame && ((FinalFrame) frame).hasThirdPitch()) { |
There was a problem hiding this comment.
instanceof를 사용하지 않고 구현할 수 있는 방법은 없을까?
There was a problem hiding this comment.
- isFinalFrame 메서드를 구현해 instanceof 조건문을 대체하는 것으로 변경하였습니다.
src/main/java/domain/ResultType.java
Outdated
| STRIKE("X", ""), | ||
| SPARE("%s", "|/"), | ||
| MISS("%s", "|%s"), | ||
| EMPTY("%d| ", ""); |
There was a problem hiding this comment.
이와 같이 구현하면 10frame은 어떻게 되는 건가요?
There was a problem hiding this comment.
- 구현할 당시 FinalFrame의 플레이방법을 잘못 이해하여 FinalFrame도 NormalFrame과 같이 2번투구까지의 결과만 보고 ResultType이 결정되게 구현하였습니다. FinalFrame의 3번투구는 ResultType의 displayFormat에 포함되어 있지 않으며
OutputView.getFrameStatus에서 별도로 처리해줍니다. - FinalFrame 플레이방법 다시 익혀 구현하면서 ResultType에서 고려되지 않는 FianlFrame의 displayFormat이 명확하도록 변경해보겠습니다.
No description provided.