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

Step2 - 사다리(생성) #985

Merged
merged 26 commits into from Aug 9, 2021
Merged

Step2 - 사다리(생성) #985

merged 26 commits into from Aug 9, 2021

Conversation

lsj8367
Copy link

@lsj8367 lsj8367 commented Aug 4, 2021

이번 리뷰도 잘 부탁드립니다.

Copy link

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

안녕하세요 승재님! 사다리 생성 미션 잘 진행해주셨네요 👍
다만 지금은 객체지향보단 절차지향에 유사한 설계 같아요
사다리 미션에서 추출할 수 있는 객체들에 대해 조금 더 고민이 필요할 것 같아요!
이 외에도 몇 가지 리뷰 남겼으니 확인 후 피드백 요청 부탁드립니다 🙇‍♂️

src/main/java/nextstep/ladder/HumanMaker.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/HumanMaker.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/HumanMaker.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/HumanMaker.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Line.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Line.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Validation.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/view/InputView.java Outdated Show resolved Hide resolved
Copy link

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

안녕하세요 승재님!

  • 원시값 포장객체와 일급컬렉션이 혼용되서 사용중인 것 같아요. 역할을 명확하게 분리해주세요
  • 사다리 생성과 관련하여 힌트 하나 남겼으니 참고해주세요

일단 지금 상태는.. 이전과 크게 다를게 없는 것 같아요. 조금 더 객체 분리에 대해 신경써주시면 좋을 것 같습니다.

src/main/java/nextstep/ladder/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Line.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Line.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/Line.java Outdated Show resolved Hide resolved
Copy link

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

안녕하세요! 피드백 반영 잘 해주셨네요.
몇 가지 리뷰 남겼는데 정리해보자면 다음과 같습니다.

  • View와 Domain을 명확하게 구분해주세요. 이번 미션을 진행하면서 반복적으로 강조하고 있는 것 같아요.
  • 이름을 명확하게 지어주세요(ex: LineStrategy -> LineCreationStrategy)
  • for/if 중첩을 제거해주세요
  • 사다리 생성 전략이 두 개로 분리되어 있는 것 같아요. 한 개로 합쳐주세요
    이상입니다!

조금만 더 힘내주세요 💪

src/main/java/nextstep/ladder/domain/AddLines.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/IsOrNoneAddLines.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderNames.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/Lines.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/Lines.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/Lines.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LineStrategy.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/Lines.java Outdated Show resolved Hide resolved
Copy link

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

안녕하세요 승재님. 피드백 내용이 거의 전혀 반영되지 않은 것 같아요 ㅠㅠ

  • 커밋 로그도 작업 단위로 나눠서 관리해주세요! 지금 한 개의 커밋에 모든 내용이 들어가있네요
  • View / Domain 이 아직 결합된 상태입니다. 분리해주세요
  • LadderName의 역할이 뭔지 다시 곰곰히 생각해보시면 좋을 것 같아요
  • Stream 미션인데 Stream에 대한 활용이 제대로 되고 있지 않은 것 같아요. Stream에 대해 조금 더 공부해보시면 어떨까요?

잘 모르겠다면 다른 분들이 어떻게 미션을 진행하고 있는지 참고해보는 것도 하나의 방법입니다!
어차피 미션 종료까지 아직 시간이 많기 때문에 천천히 고민해보셔도 좋을 것 같아요.
몇 차례 피드백 요청 보내주시고, 피드백을 하고 있는데 의미있는 개선이 거의 보이지 않는 것 같아요.. ㅠㅠ

src/main/java/nextstep/ladder/domain/LadderName.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderNames.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderNames.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderNames.java Outdated Show resolved Hide resolved
src/main/java/nextstep/ladder/domain/LadderNames.java Outdated Show resolved Hide resolved
Comment on lines +42 to +44
public int size() {
return this.ladderNames.size();
}

Choose a reason for hiding this comment

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

Suggested change
public int size() {
return this.ladderNames.size();
}
public int size() {
return ladderNames.size();
}

this는 생략해도 괜찮을 것 같아요.

src/main/java/nextstep/ladder/domain/Line.java Outdated Show resolved Hide resolved
Comment on lines +10 to +26
public Lines(List<Line> lines, int maxNum, LineCreationStrategy lineCreationStrategy) {
this.lines = lines;
this.lines = drawLine(maxNum, lineCreationStrategy);
}

public static Lines of (List<Line> lines, int maxNum, LineCreationStrategy lineCreationStrategy) {
return new Lines(lines, maxNum, lineCreationStrategy);
}

private List<Line> drawLine(int maxNum, LineCreationStrategy lineCreationStrategy) {

for (int i = 1; i < maxNum; i++) {
drawLine(lineCreationStrategy);
}

return lines;
}

Choose a reason for hiding this comment

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

LadderNames에 남겨놓은 피드백을 참고로해서 이부분도 개선해주세요

Copy link

@JunilHwang JunilHwang left a comment

Choose a reason for hiding this comment

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

안녕하세요 승재님! 피드백 반영 잘 해주셨네요 👍
몇 가지 피드백 남겼으니 확인해보시면 될 것 같습니다.

일단 핵심적인 이야기만 몇 가지 하자면,

  • 테스트코드가 너무 빈약해요.
    • 도메인 객체가 매우 많은데 지금은 두 개의 도메인에 대해서만 테스트하고 있네요.
    • 모든 도메인 객체의 메소드에 대해 테스트할 수 있도록 작성해보세요!
  • 항상 네이밍에 신경써주세요!
    • 객체를 정확하게 묘사하고 있는지 고민해보세요!

Step2는 여기서 마무리하겠습니다.
피드백은 Step3 진행하면서 참고해보시면 좋을 것 같아요.
고생하셨습니다!

Comment on lines +5 to +15
public class LadderLineCreationStrategy implements LineCreationStrategy {
@Override
public boolean createLine() {
return getRandomNum();
}

private boolean getRandomNum() {
Random random = new Random();
return random.nextBoolean();
}
}

Choose a reason for hiding this comment

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

LadderLineCreationStrategy은 너무 포괄적인 이름이 아닐까요? 행위를 구체적으로 묘사해주세요!

Comment on lines +11 to +18
public LadderName(String ladderName) {
this.laddername = ladderName;
}

public static LadderName of(String ladderName) {
lengthValidation(ladderName);
return new LadderName(ladderName);
}

Choose a reason for hiding this comment

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

Suggested change
public LadderName(String ladderName) {
this.laddername = ladderName;
}
public static LadderName of(String ladderName) {
lengthValidation(ladderName);
return new LadderName(ladderName);
}
private LadderName(String ladderName) {
this.laddername = ladderName;
}
public static LadderName of(String ladderName) {
lengthValidation(ladderName);
return new LadderName(ladderName);
}

어차피 of가 똑같은 역할을 하고 있기 때문에 생성자는 private으로 지정해주세요!
무엇보다 생성자에 검증로직이 없기 때문에 of를 통해서만 인스턴스를 만들 수 있도록 해야합니다.


private static void lengthValidation(String name) {
if(name.length() > LETTER_LIMIT) {
throw new StringLengthException();

Choose a reason for hiding this comment

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

StringLengthException이란 이름 또한 굉장히 포괄적인 이름이 아닐까요?

Comment on lines +4 to +6
INITLINE(false),
NONELINE(false),
ISLINE(true);

Choose a reason for hiding this comment

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

Suggested change
INITLINE(false),
NONELINE(false),
ISLINE(true);
IN_IT_LINE(false),
NONE_LINE(false),
IS_LINE(true);

이렇게 구분해줘야 읽기 쉬울 것 같아요!

Comment on lines +8 to +13
private List<Line> lines;

public Lines(List<Line> lines, int maxNum, LineCreationStrategy lineCreationStrategy) {
this.lines = lines;
this.lines = drawLine(maxNum, lineCreationStrategy);
}

Choose a reason for hiding this comment

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

Suggested change
private List<Line> lines;
public Lines(List<Line> lines, int maxNum, LineCreationStrategy lineCreationStrategy) {
this.lines = lines;
this.lines = drawLine(maxNum, lineCreationStrategy);
}
private final List<Line> lines;
private Lines(List<Line> lines) {
this.lines = lines;
}

이전 리뷰에도 남겼는데 이렇게 표현할 수 있도록 개선해보세요!
지금은 코드가 무척 부자연스러워보이네요

Comment on lines +41 to +48
private void previousCheck(LineCreationStrategy lineCreationStrategy) {

if (lineCreationStrategy.createLine()) {
lines.add(Line.NONELINE);
return;
}
lines.add(Line.ISLINE);
}

Choose a reason for hiding this comment

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

이 로직은 생성로직입니다.
이 부분 또한 Strategy에게 위임해보세요.

Comment on lines +13 to +78
public class ResultView {
private static final int LETTER_LIMIT = 5;
private static final String SPACE = " ";
private static final String REPLACE_STRING = "\\[|\\]";
private static final String INIT_LINE = " |";
private static final String NONE_LINE = " |";
private static final String IS_LINE = "-----|";

public void print(LadderNames ladderNames, int maxLadderHeight) {
printLadderName(ladderNames);
printLadderLines(ladderNames, maxLadderHeight);
}

private static List<String> makeLine(List<Line> lines) {
return lines.stream()
.map(ResultView::drawLine)
.collect(Collectors.toList());
}

private static String drawLine(Line line) {
if (line == Line.INITLINE) {
return INIT_LINE;
}

if(line.isExist()) {
return IS_LINE;
}

return NONE_LINE;
}

public void printLadderLines(LadderNames ladderNames, int maxLadderHeight) {
for(int i = 0; i < maxLadderHeight; i++) {
printLines(Lines.of(initLine(), ladderNames.size(), new LadderLineCreationStrategy()));
}
}

private void printLines(Lines lines) {
System.out.println(makeLine(lines.getLines())
.toString()
.replaceAll(REPLACE_STRING, "")
.replaceAll(", ", ""));
}

public void printLadderName(LadderNames ladderNames) {
Object[] names = Arrays.stream(ladderNames.toString().split(","))
.map(this::fitLength)
.toArray();

System.out.println(Arrays.toString(names).replaceAll(REPLACE_STRING, "").replaceAll(",", ""));
}

private String fitLength(String name) {
if(name.length() < LETTER_LIMIT) {
name = fitLength(SPACE.concat(name));
}

return name;
}

private List<Line> initLine() {
List<Line> lines = new ArrayList<>();
lines.add(Line.INITLINE);
return lines;
}
}

Choose a reason for hiding this comment

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

어차피 멤버변수가 없기 때문에 전부 static method로 표현해도 무방할 것 같아요.
혹은 싱글톤으로 관리해주면 더 좋을 것 같습니다.

Comment on lines +44 to +63
public void printLadderLines(LadderNames ladderNames, int maxLadderHeight) {
for(int i = 0; i < maxLadderHeight; i++) {
printLines(Lines.of(initLine(), ladderNames.size(), new LadderLineCreationStrategy()));
}
}

private void printLines(Lines lines) {
System.out.println(makeLine(lines.getLines())
.toString()
.replaceAll(REPLACE_STRING, "")
.replaceAll(", ", ""));
}

public void printLadderName(LadderNames ladderNames) {
Object[] names = Arrays.stream(ladderNames.toString().split(","))
.map(this::fitLength)
.toArray();

System.out.println(Arrays.toString(names).replaceAll(REPLACE_STRING, "").replaceAll(",", ""));
}

Choose a reason for hiding this comment

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

상수로 표현할 수 있는 것들이 많은 것 같아요!

Comment on lines +20 to +26
@Test
@DisplayName("이름 5글자 예외처리")
void ladderExceptionTest() {
assertThatThrownBy(() -> LadderNames.of("pobiaaaaa,honux,crong,jk"))
.hasMessageContaining("5글자")
.isInstanceOf(StringLengthException.class);
}

Choose a reason for hiding this comment

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

이건 LadderName에서 테스트해야하지 않을까요?

Comment on lines +14 to +45
public class LinesTest {
List<Line> list;

@BeforeEach
void setUp() {
list = new ArrayList<>();
list.add(Line.INITLINE);
}

@Test
@DisplayName("사다리 줄 생성 true")
void makeLineTest() {
int height = 5;

for(int i = 0; i < height; i++) {
Lines lines = Lines.of(list, 4, () -> true);
assertThat(lines).isEqualTo(Lines.of(list, 4, () -> true));
}
}

@Test
@DisplayName("사다리 줄 생성 false")
void makeLineFalseTest() {
int height = 5;

for(int i = 0; i < height; i++) {
Lines lines = Lines.of(list, 3, () -> false);
assertThat(lines).isEqualTo(Lines.of(list, 3, () -> false));
}
}

}

Choose a reason for hiding this comment

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

Line에 대한 테스트 코드가 없네요 ㅠ
테스트 코드가 전체적으로 빈약합니다.

@JunilHwang JunilHwang merged commit 774d817 into next-step:lsj8367 Aug 9, 2021
@lsj8367 lsj8367 deleted the step2 branch August 9, 2021 23:43
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.

None yet

2 participants