Skip to content

Conversation

@hansolnoh95
Copy link

No description provided.

Copy link

@KimGyeong KimGyeong 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 10
static private final String ADD_OPERATION = "+";
static private final String SUBTRACT_OPERATION = "-";
static private final String MULTIPLY_OPERATION = "*";
static private final String DIVIDE_OPERATION = "/";
static private final int NUMBER_INDEX = 0;
static private final int OPERATION_INDEX = 1;

Choose a reason for hiding this comment

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

Suggested change
static private final String ADD_OPERATION = "+";
static private final String SUBTRACT_OPERATION = "-";
static private final String MULTIPLY_OPERATION = "*";
static private final String DIVIDE_OPERATION = "/";
static private final int NUMBER_INDEX = 0;
static private final int OPERATION_INDEX = 1;
private static final String ADD_OPERATION = "+";
private static final String SUBTRACT_OPERATION = "-";
private static final String MULTIPLY_OPERATION = "*";
private static final String DIVIDE_OPERATION = "/";
private static final int NUMBER_INDEX = 0;
private static final int OPERATION_INDEX = 1;

private는 접근제어자입니다. 모든 선언에서 접근제어자는 맨 처음으로 나와주어야 합니다.

Comment on lines 12 to 14
List<String> numberList = new ArrayList<>();
List<String> operationList = new ArrayList<>();
int result = 0;

Choose a reason for hiding this comment

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

Calculator의 필드변수들입니다. 접근제어자를 작성해주지 않으면 default라는 접근제어자가 기본값으로 적용됩니다. default는 같은 패키지 내의 다른 클래스가 사용할 수 있습니다. 다른 클래스에서 접근하지 못하게 private으로 변경해주세요.

Comment on lines +37 to +39
validation(line);
addNumberList(line);
addOperationList(line);

Choose a reason for hiding this comment

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

Calculator클래스의 메소드 중 다른 클래스에서 사용하는 메소드는 execute() 단 하나입니다.
그래서 이 메소드들의 접근제어자를 private으로 변경하는게 좋을 수 있습니다.
단, private 메소드들은 테스트를 하기 어려워집니다. 테스트 클래스에서 바로 호출할 수 없기 때문이죠.
execute()와 같은 메소드가 존재할 경우에 발생하는 문제는 이렇습니다. 이 메소드가 수행하는 로직을 main()에서 진행하는 것을 권장합니다.

Copy link
Author

Choose a reason for hiding this comment

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

Calculator 내에 main()을 만들라는 말인가여?

Choose a reason for hiding this comment

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

main 메소드의 길이를 신경쓰지 않으셔도 된다는 말이에요. 제 개인적인 의견이지만 main에서 이 프로그램이 어떻게 흘러가는지를 알 수 있게끔 구현해도 괜찮다고 생각합니다.
추가적으로 공식에 대한 예외처리를 과연 Calculator가 해야하는 지에 대한 의문도 드네요.

import java.util.Scanner;

public class Input {
public static final String BLANK = " ";

Choose a reason for hiding this comment

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

Suggested change
public static final String BLANK = " ";
private static final String BLANK = " ";

접근제어자를 변경해주세요.

}
}

public static String[] getStream() {

Choose a reason for hiding this comment

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

메소드명의 의미 전달이 불확실합니다. 메소드명을 변경해주세요.

System.out.println(result);
}
public static void printError(Exception e) {
System.out.println("출력 에러");

Choose a reason for hiding this comment

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

메소드명으로 에러를 출력함을 알 수 있는데, 어떤 에러인지 알 수 없습니다. 메소드명을 변경해주세요.

}

public void validation(String line[]) {
if (line.length%2 == 0) throw new RuntimeException("올바른 식을 완성해주세요.");

Choose a reason for hiding this comment

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

조건문은 어떤 것을 의미할까요? 이 메소드만 보았을 때에 입력받은 line의 길이가 짝수이면 올바른 식이 아니라는 말로 받아들일 수 있는데, line은 어떤 것을 의미하는지 모를 수 있겠네요.

return result;
}

public void validation(String line[]) {

Choose a reason for hiding this comment

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

Suggested change
public void validation(String line[]) {
public void validation(String[] line) {

Array의 선언은 일반적으로 타입뒤에 대괄호를 붙입니다. 아래도 동일하게 변경해주세요.

public class Input {
public static final String BLANK = " ";

public static String getInput() {

Choose a reason for hiding this comment

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

이처럼 'get'으로 시작하는 메소드는 클래스의 필드값을 반환해주는 로직을 수행하는 것을 권장합니다. 메소드명을 변경해주세요. 어떤 것을 입력받는지에 대해 알려주면 좋을 것 같습니다.

Copy link

@KimGyeong KimGyeong 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 +37 to +39
validation(line);
addNumberList(line);
addOperationList(line);

Choose a reason for hiding this comment

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

main 메소드의 길이를 신경쓰지 않으셔도 된다는 말이에요. 제 개인적인 의견이지만 main에서 이 프로그램이 어떻게 흘러가는지를 알 수 있게끔 구현해도 괜찮다고 생각합니다.
추가적으로 공식에 대한 예외처리를 과연 Calculator가 해야하는 지에 대한 의문도 드네요.

}
}

public static String[] getFormattedInput() {

Choose a reason for hiding this comment

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

이 메소드 또한 이전의 코멘트처럼 get으로 시작하는 메소드이네요. input으로 시작하는 이름으로 지으면 헷갈리는 일이 덜 발생할 것이라고 생각해요.

Comment on lines +47 to +49
private void validation(String[] formattedInput) {
if (formattedInput.length%2 == 0) throw new RuntimeException("올바른 식을 완성해주세요.");
}

Choose a reason for hiding this comment

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

개발자가 편하면 사용자가 불편하다.라고 생각해요. 올바른 식은 어떤 것일까요? 숫자 두 개를 연속으로 입력한 식은 올바른 식일까요? 연산자 두 개를 연속으로 입력한 식은 올바른 식일까요? 예외에 대해 조금 더 깊게 생각해보는 것도 중요하다고 생각합니다.

Comment on lines +12 to +14
private List<String> numberList = new ArrayList<>();
private List<String> operationList = new ArrayList<>();
private int result = 0;

Choose a reason for hiding this comment

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

이렇게 인스턴스 변수를 초기화하는 것을 명시적 초기화라고 합니다. 생성자를 통해 인스턴스 변수를 초기화 할 수 있습니다. 인스턴스 변수 초기화의 방법은 4가지가 있고, 각 초기화가 실행되는 시점이 다릅니다. 이를 알고 있으면 좋을 것 같아요.

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