Skip to content

[1단계 - 사다리 생성] 에단(김석호) 미션 제출합니다.#107

Merged
iphwade merged 25 commits intowoowacourse:cookiencfrom
cookienc:step1
Feb 19, 2023
Merged

[1단계 - 사다리 생성] 에단(김석호) 미션 제출합니다.#107
iphwade merged 25 commits intowoowacourse:cookiencfrom
cookienc:step1

Conversation

@cookienc
Copy link
Copy Markdown

안녕하세요😄 코일! 이번에 준팍(박준현)과 페어로 같이한 사다리 미션 제출합니다!
이번 미션에서는 SRP 원칙과 모든 원시값을 포장하려고 노력했습니다. 코드 리뷰 미리 감사드립니다.
추가로 궁금한 프로그래밍을 하면서 궁금한 사항이 있어서 질문을 남깁니다!

  1. 사용자의 입력 처리 로직은 Controller, InputView 중에서 어떤 곳에 위치를 시켜야 할까요?
  • 예외를 가장 가까운 곳에서 처리한다는 목적으로 생각해 본다면 InputView에서 처리하는게 낫다고 생각합니다. 반면에 Controller에 모든 예외가 모이는 관점에서 보면 Controller에서 처리하는게 낫다고 생각됩니다. 코일의 생각은 어떠신가요?
  1. 원시값을 포장할 때 어느 정도까지 포장을 해야하는지 궁금합니다.
  • 저희의 코드를 보면 Line에서 리스트의 마지막 값을 구할 때 siz() - 1을 사용하는데 이 때 사용한 1도 포장을 해야하는지 궁금합니다.

junpakPark and others added 24 commits February 14, 2023 16:14
Copy link
Copy Markdown

@iphwade iphwade left a comment

Choose a reason for hiding this comment

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

안녕하세요-!
코드 리뷰를 하게된 코일입니다.
전체적으로 짜임새있고 클래스 분리, 메서드 분리가 잘 되어있어서 리뷰드릴 부분이 적네요-!
고생하셨습니다-!

사용자의 입력 처리 로직은 Controller, InputView 중에서 어떤 곳에 위치를 시켜야 할까요?
-> 예외 처리에 적절한 클래스가 어디일지를 고민해보면 좋을 것 같습니다. Controller에 모든 예외가 모이면 좋은 이유가 뭐라고 생각하실까요-?! 반대로 발생하는 곳에서 가장 가까운 InputView에서 처리하면 좋은 점이 뭐라고 생각하실까요-?!

원시값을 포장할 때 어느 정도까지 포장을 해야하는지 궁금합니다.
-> 1을 상수화하는 것이 원시값을 포장을 의미하는 것은 아니라고 생각합니다. 원시값의 포장은 해당 원시값이 충분한 메서드 (역할)을 가질 때 필요합니다. 말씀하신 예시는 매직넘버를 어떻게 처리할지에 대한 질문인 것 같습니다-! lastIndex로 네이밍된 변수가 충분히 표현이 된다고 생각되어 지금은 괜찮다고 보여집니다-!

다른 질문이 있으시면 편하게 DM주세요-!

static class NameLengthTest {
@DisplayName("1 이상 5 이하 글자가 들어오면 name이 정상적으로 생성된다.")
@ParameterizedTest
@ValueSource(strings = {"에단", "준팍"})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

테스트는 경계값을 위주로 테스트해보면 어떨까요?


//then
Assertions.assertThat(result)
.extracting("names")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

names 변수명이 변경이되면 이 테스트는 실패하겠군요-!

Copy link
Copy Markdown
Author

@cookienc cookienc Feb 18, 2023

Choose a reason for hiding this comment

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

view에서 getter를 사용하기 때문에 테스트에서도 getter를 사용하도록 수정했습니다.

@DisplayName("너비가 1 미만이면 예외가 발생한다")
void givenOneLessWidth_thenFail() {
assertThatThrownBy(() -> new Line(0))
assertThatThrownBy(() -> Line.from(0))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

정적 팩토리 메서드 이름에도 신경을 쓰셨군요! 👍

try {
random = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
System.out.println(e.getMessage());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

에러를 프린트하는 이유가 있나요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

처음에는 try-catch하고 에러를 프린트하는 것이 익숙해서 이렇게 만들었었습니다.😅 하지만 생각해보니 프린트 문을 없애는게 더 적절하다고 생각이 듭니다. 에러를 프린트해서 ‘사용자’에게 알려주는 것은 사용자의 입력이 잘못되었을 때 사용자에게 인식을 시키기 위해서입니다. 현재 작성된 코드를 보면 예외가 발생하는 경우는 랜덤 객체가 생성되지 않는 경우 입니다. 그렇다면 이 경우는 사용자의 입력과 관련 없는 서버 문제가 됩니다. 따라서 이 코드에서 사용하는 print는 사용자에게 알려주는 것이 아니라 log의 의미로 해석이 될 수 있기 때문에 없어지는 것이 적절하다고 생각이 됩니다.

Comment on lines +16 to +18
public List<Line> getLines() {
return Collections.unmodifiableList(lines);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Getter 컨벤션 수정이 필요해보입니다-!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Getter 컨벤션이 무엇인지 알 수 있을까요?ㅜㅜ 찾아봐도 정보가 나오지 않네요. 관련해서 학습할 자료가 있다면 추천해주세요!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@cookienc

https://dodop-blog.tistory.com/277를 기준으로 삼으면 좋아보입니다-!

}

@ParameterizedTest
@ValueSource(strings = {"에단", "준팍", "또링", "코일", "블랙캣", "백여우"})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧑‍🎤


private void validateNUmberOfNames(final List<String> names) {
if (names.size() < 2) {
throw new IllegalArgumentException();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

에러 메세지를 명시하지 않은 이유가 있을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

일단은 돌아가는 코드를 만들고 수정하자라는 생각을 가지고 코딩을 했습니다!! 지금은 에러메세지가 있는 상태로 수정되었습니다😄

Comment on lines +28 to +30
public List<Boolean> getStatuses() {
return new ArrayList<>(statuses);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

statuses를 그냥 반환하지 않은 이유가 뭘까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

방어적 복사를 함으로써 원본 객체를 보호하기 위해서 입니다. 물론 방어적 복사가 깊은 복사가 아니기 때문에 완벽히 방어할 수는 없습니다. 다만 getter를 쓰는 곳에서 추가나 삭제 시 원본을 방어하는 것도 충분히 의미가 있어보여서 사용했습니다.

@cookienc
Copy link
Copy Markdown
Author

안녕하세요. 코일! 반영사항에 대해서 코멘트 남겼습니다. 그리고 질문에 대해서 제 생각을 남깁니다.

  • Controller에서 예외 처리 → 애플리케이션의 흐름을 관리하는 역할이라는 점에서 부합
    • 장점 : 예외 처리 로직을 변경할 때 Controller만 수정하면 로직을 수정할 수 있게 됩니다.
    • 단점 : 흐름을 관리하는 역할이지만 잦은 try - catch 문을 사용해서 코드의 가독성을 해칠 수 있다.
  • InputView에서 예외 처리 → Input과 관련된 내용을 관리하는 역할이라는 점에서 부합
    • 장점 : 예외 처리 로직을 변경할 때 InputView만 수정하면 로직을 수정할 수 있게 됩니다
    • 단점 : 도메인에서 validate를 진행할 시, 도메인과 연관관계가 생성됩니다.
      => 위의 장단점을 보아 장점은 서로 비슷하지만 단점의 경우 InputView의 경우가 더 안좋기 때문에 Controller에서 오류를 처리하는 쪽이 더 나은것 같습니다.

@iphwade iphwade merged commit 0b4d138 into woowacourse:cookienc Feb 19, 2023
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.

3 participants