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

[사다리 미션] 허준기 미션 제출합니다. #4

Open
wants to merge 6 commits into
base: dradnats1012
Choose a base branch
from

Conversation

dradnats1012
Copy link

리팩토링이 좀 더 필요한 것 같은데 일단 기능은 전부 구현했습니다!
조금씩 좀 더 수정해보겠습니당
피드백 부탁드려요~

3단계까지는 쉬웠는데 4단계에서 좀 정체됐네요ㅠㅠ

Copy link

@seongjae6751 seongjae6751 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 +8
public interface LadderGenerator {

List<Line> generateLadder();
}
Copy link

@seongjae6751 seongjae6751 Jul 20, 2024

Choose a reason for hiding this comment

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

generator를 따로 분리 하시는 것을 선호 하게 된 이유나 많은 생각들이 있으셨을 것 같은데 어떤 생각들이 있으셨는지 궁금합니다..!

Copy link
Author

Choose a reason for hiding this comment

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

예전에 자동차 경주 미션을 진행할 때 랜덤값에 대한 테스트를 진행했었는데 다른 친구의 얘기를 듣고 고민을 해보니 결국 랜덤값은 프로그램의 영역이라 테스트를 해도 의미가 없다는 생각이 들었습니다
그래서 랜덤값 테스트를 하지 않고 자동차의 기능을 테스트를 하려고 보니 자동차의 움직임이 랜덤값에 의존하다보니 테스트 할때마다 다른 결과가 나오게 되는 상황이 발생했습니다

그때 전략패턴이라는 객체지향 패턴을 알게 되었고 이를 통해서 숫자를 생성해주는 방식을 인터페이스를 통해 관리하고 테스트를 진행할 때 해당하는 전략에 맞춰서 테스트를 실행할 수 있어서 이런식으로 분리하는 습관이 생긴 것 같아요!!

Comment on lines +18 to +25
private void generateLine() {
while (checkEmpty()) {
for (int i = 0; i < width - 1; i++) {
points.add(random.nextBoolean());
checkLeft(i);
}
}
}

Choose a reason for hiding this comment

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

ladder는 generator를 따로 만들고 line은 클래스 내에서 generate하는 이유가 혹시 따로 있으실까요??

Copy link
Author

Choose a reason for hiding this comment

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

아 이건 1단계 미션 힌트에 Line을 따로 구현해보라고 써있어서 그렇게 한번 해봤습니다!
처음에는 그냥 generator에서 2차원배열로 전부 구현하려고 했는데 이렇게 나누니까 편하더라구요

import java.util.Map;

public class ResultMap {
private final Map<String, String> resultMap = new LinkedHashMap<>();

Choose a reason for hiding this comment

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

저는 linkedhashmap을 사용할 생각은 해보지 못했는데 재밌게 잘 구현하셨네요👍👍

Comment on lines +3 to +10
public enum ConsoleMessage {
RESULT("실행결과"),
LADDER_RESULT("사다리 결과"),
LADDER_WIDTH("사다리의 넓이는 몇 개인가요?"),
LADDER_HEIGHT("사다리의 높이는 몇 개인가요?"),
INPUT_NAME("참여할 사람 이름을 입력하세요. (이름은 쉼표(,)로 구분하세요)"),
INPUT_RESULT("실행 결과를 입력하세요. (결과는 쉽표(,)로 구분하세요)"),
RESULT_TARGET("결과를 보고 싶은 사람은?");

Choose a reason for hiding this comment

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

console 메시지를 이렇게 enum으로 분리하시는 것도 선호하시는 것 같아요..!
이것도 다른 사람 코드에는 많이 나타나지 않는 재밌는 특징 같은데 이렇게 분리하게 된 생각의 과정이 궁금합니다..!

Copy link
Author

Choose a reason for hiding this comment

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

그냥 뭔가 코드에 한글이 들어가니까 이질감이 들어서 아예 메시지 열거형을 하나 만들어서 관리하면 어떨까 라는 생각에 만들어 봤습니다!
한번 해보니까 편해서 쭉 그렇게 사용하고 있어요!

Comment on lines +30 to +35
if (result.getResult() instanceof Map) {
OutputView.printResult((Map<String, String>)result.getResult());
}
if (result.getResult() instanceof String) {
OutputView.printResult((String)result.getResult());
}

Choose a reason for hiding this comment

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

instanceof 연산자 사용하신 것도 재밌네요
솔직히 잘 사용 안해서 잊고 있던 연산자 인데 재밌게 잘 구현하신 것 같습니다

Copy link
Author

Choose a reason for hiding this comment

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

메서드 오버로딩으로 하려고 하다가 타협점을 찾은게 instanceof입니다 ㅠㅠ
개인적으로 이부분에서 약간 지저분해진것 같아요ㅠㅠㅠㅠ

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