Skip to content

Conversation

@zangsu
Copy link

@zangsu zangsu commented Nov 30, 2023

No description provided.

while(true) {
view.printMenuView();
String input = scanner.nextLine();
if (input.equals("Q")) {
Copy link

Choose a reason for hiding this comment

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

리터럴 및 입력을 비교할 때, "Q".equals(input)과 같은 방식으로 코드를 작성하면 어떨까 합니다.

Scanner에 의해 입력 받는 값이 null이 될 수는 없기 때문에 해당 코드에서 NPE가 발생하진 않겠으나,

Scanner가 아닌 다른 null이 될 가능성이 있는 String 타입의 변수를 리터럴과 비교 연산할 때, NPE를 막아줄 수 있겠습니다.

이러한 규칙을 코딩 표준으로 만들어서 항상 literal.equals(variable) 구조로 작성한다면, 일관적인 스타일로 코드를 작성하면서 NPE을 방지할 수 있을 것 같습니다.

private static void findPath(Scanner scanner) {
view.printPathMenu();
String input = scanner.nextLine();
if (input.equals("B")) {
Copy link

Choose a reason for hiding this comment

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

여러 Command를 모두 String Literal 형태로 Controller 내에서 관리하고 있는데, 각 Command의 카테고리에 맞게 enum을 별도로 생성하고 검증해주면 좋을 것 같습니다.

이점은 각 Command에 대한 테스트를 작성하기에 유리하고, 여러 파일에서 문자열 리터럴을 관리하는 것보다 유지 보수 향상, 실수 방지 및 파악에 용이해진다는 점이 있다고 생각합니다.

enum만 들어가도 각 Command에 대한 상태를 모조리 볼 수 있으니까요.

@june-777 님의 ApplicationStatus 등을 참고하시면 도움이 될 것 같습니다.

시간 단축을 위해 작성하셨을 수도 있을 것 같은데, Commandenum화 하는게 좀 더 좋은 인상을 줄 수 있을 것 같아서 처음에 이렇게 작성하고 일단 작동 시킨 뒤에 리팩토링 하는 방향도 좋을 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

맞습니다,,, 리팩토링을 하고싶었지만 시간이 부족해 하지 못했던 부분이네요 ㅠ

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