-
Notifications
You must be signed in to change notification settings - Fork 0
문자열 계산기 미션 🧮 #1
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
base: main
Are you sure you want to change the base?
문자열 계산기 미션 🧮 #1
Changes from all commits
04a0c88
39e1c1c
629533e
aa5a17c
0c77f38
4b9d17d
34a8b9f
2c9b9fd
59f68c4
cbe76f4
e3fc33f
6bf86de
c4b4a6d
2ebbda8
b8a4054
de3c373
e6b1ba7
f23ecb8
5514eca
69c6344
9e503af
05971be
4852356
d599266
417abf7
a1fbb56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1 +1,62 @@ | ||||||
| # java-calculator-precourse | ||||||
| # java-calculator-precourse | ||||||
|
|
||||||
| ## 미션 목표 | ||||||
|
|
||||||
| - 🔺 OOP(Object Oriented Programming) | ||||||
| - ✅ TDD 실습 | ||||||
|
|
||||||
| ## 미션 요구사항 | ||||||
|
|
||||||
| 입력한 문자열에서 숫자를 추출해 더하는 계산기를 만든다. | ||||||
|
|
||||||
| - 기본 구분자인 쉼표`,`나 콜론`:`을 구분자로 가지는 문자열을 받으면 구분자를 기준으로 숫자를 분리한 후 숫자를 더한 값을 반환한다. | ||||||
| - 기본 구분자 외에 커스텀 구분자를 `//`와 `\n`에 정의하여 사용할 수 있다. | ||||||
| - 잘못된 값을 입력할 경우 `IlLegaLArgumentException`을 발생시킨 후 종료된다. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오타가 있었군요! 감사합니다 👍🏻 |
||||||
|
|
||||||
| ## 구현 기능 목록 | ||||||
|
|
||||||
| ### 입력 | ||||||
|
|
||||||
| - [x] 구분자와 양수로 구성된 문자열을 입력받는다. | ||||||
|
|
||||||
| ### 구분자 확인 | ||||||
|
|
||||||
| - [x] 기본 구분자인지 커스텀 구분자인지 확인한다. | ||||||
|
|
||||||
| ### 문자열 분리 | ||||||
|
|
||||||
| - [x] 구분자를 기준으로 숫자를 분리한다. | ||||||
|
|
||||||
| ### 문자열 계산 | ||||||
|
|
||||||
| - [x] 추출된 문자열을 숫자로 변환한 후 더한다. | ||||||
|
|
||||||
| ### 예외 상황 | ||||||
|
|
||||||
| - [x] 기본 구분자도 커스텀 구분자도 아닌 경우 | ||||||
| - [x] `,`와 `:` 외의 구분자를 사용한 경우 | ||||||
| - [x] `//`와 `\n`의 형식을 지키지 않은 경우 | ||||||
| - 음수를 입력한 경우 | ||||||
| - 사용할 수 없는 구분자를 사용한 경우 ex) 숫자, 커스텀 구분자 형식 (`// \n`), 공백 | ||||||
|
|
||||||
| ## 예제 | ||||||
|
|
||||||
| | 입력 | 출력 | | ||||||
| |--------------|-----| | ||||||
| | `""` | `0` | | ||||||
| | `1` | `1` | | ||||||
| | `1,2,3` | `6` | | ||||||
| | `1,2:3` | `6` | | ||||||
| | `1:2:3` | `6` | | ||||||
| | `//;\n1;2;3` | `6` | | ||||||
|
|
||||||
| ## 예외 예제 | ||||||
|
|
||||||
| | 입력 | 예외 (`IllegalArgumentException`) | | ||||||
| |---------------|---------------------------------| | ||||||
| | `1,2,-3` | `양수를 입력해주세요` | | ||||||
| | `1,2;3` | `기본 구분자(,나 :)를 사용해주세요.` | | ||||||
| | `1,a,3` | `숫자만 입력해주세요.` | | ||||||
| | `//;1;2;3` | `커스텀 구분자 형식에 맞게 입력해주세요.` | | ||||||
| | `//\n123` | `커스텀 구분자를 입력해주세요.` | | ||||||
| | `//1\n112131` | `사용 가능한 커스텀 구분자를 입력해주세요.` | | ||||||
|
Comment on lines
+53
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지윤님은 어떤 장점을 위해 예외 상황을 문서로 관리하는 것을 선택하셨나요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README를 보고 제가 생각한 예외 상황에 대해서 명시하기 위해서 작성했습니다! 그렇다면 예혁님은 테스트 코드로만 예외 상황을 표현하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
요구사항을 보고 생각했던 예외를 말씀 하신 걸까요? 그리고 어떤 장점이 있었기에 명시하려고 하셨나요?
README는 결국 저는 |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| package calculator; | ||
|
|
||
| import calculator.controller.CalculatorController; | ||
| import calculator.model.Calculator; | ||
| import calculator.model.DelimiterExtractor; | ||
| import calculator.model.StringSplitter; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| CalculatorController calculatorController = new CalculatorController( | ||
| new DelimiterExtractor(), | ||
| new StringSplitter(), | ||
| new Calculator() | ||
| ); | ||
| calculatorController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package calculator.controller; | ||
|
|
||
| import calculator.model.Calculator; | ||
| import calculator.model.DelimiterExtractor; | ||
| import calculator.model.Parser; | ||
| import calculator.model.StringSplitter; | ||
| import calculator.view.InputView; | ||
| import calculator.view.OutputView; | ||
| import camp.nextstep.edu.missionutils.Console; | ||
| import java.util.List; | ||
|
|
||
| public class CalculatorController { | ||
|
|
||
| private final DelimiterExtractor delimiterExtractor; | ||
| private final StringSplitter stringSplitter; | ||
| private final Calculator calculator; | ||
|
|
||
| public CalculatorController(final DelimiterExtractor delimiterExtractor, | ||
| final StringSplitter stringSplitter, | ||
| final Calculator calculator) { | ||
| this.delimiterExtractor = delimiterExtractor; | ||
| this.stringSplitter = stringSplitter; | ||
| this.calculator = calculator; | ||
| } | ||
|
Comment on lines
+12
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 객체들을 Controller의 상태(필드)로 가져야 하는 이유가 있나요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 흐름을 제어하기 위해 필요하다고 판단해서 객체를 주입하는 방식으로 선택했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이 부분이 조금 추상적으로 느껴졌어요. 혹시 어떤 흐름을 말씀하신 건가요? 그 객체(DelimiterExtractor, StringSplitter 등)가 필요했다면, |
||
|
|
||
| public void run() { | ||
| String input = InputView.getInput(); | ||
| if (isCheckedEmptyOrNull(input)) { | ||
| return; | ||
| } | ||
|
|
||
| List<String> delimiters = delimiterExtractor.extract(input); | ||
| List<String> numbers = stringSplitter.split(input, delimiters); | ||
| List<Integer> parsedNumbers = Parser.parse(numbers); | ||
|
|
||
| int result = calculator.add(parsedNumbers); | ||
| OutputView.printResult(result); | ||
| Console.close(); | ||
| } | ||
|
|
||
| private boolean isCheckedEmptyOrNull(final String input) { | ||
| if (input == null || input.isBlank()) { | ||
| OutputView.printResult(0); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
Comment on lines
+41
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 입력값이 빈문자열인 경우 아무 연산을 수행하지 않고, 바로 0을 반환하도록 구성한 것은 효율적인 방법일 수 있어요. 👍 👍 예를 들어, 숫자를 1만 입력하면 그대로 1을 출력하도록 하는 것도 Controller에서 처리해준다면 여러 계산이나 구분자 처리 없이 가능하지 않을까요? 0으로 반환 또는 특수한 입력을 처리하는 로직이 늘어난다면 어떻게 될까요? 저는 오히려 예상하지 못한 곳에 코드가 존재하게될 확률이 높아질 것 같아요. Controller가 아닌 모델이 책임질 수 있도록 설계하면 어떨까요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 이 의견에 동의하는 것 같아요. 아무것도 입력하지 않았을 때 최대한 적은 접근으로 반환하려 하다보니 Controller에 두게 됐네요! |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package calculator.model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Calculator { | ||
|
|
||
| public int add(List<Integer> values) { | ||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문자열 계산기 프로젝트에서 계산기 객체가 중요할 것 같다고 판단했는데,
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 각 클래스가 책임에 따라 역할을 명확히 나누는 데 중점을 두었고, 하지만, 예혁님 피드백을 보고 리뷰를 제가 잘 이해하고 대답한 건지 모르겠네요 .. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
각 클래스가 책임에 따라 역할을 명확히 나누는 데 중점을 두셨고, 지금 구조를 보면 Controller가 여러 객체들을 직접 조립하고 호출하는 방식이에요. Calculator는 단순히 List를 더하는 역할만 수행하고 있어서, 조금 더 객체들 간에 역할을 분산시키고, 서로 |
||
| int result = 0; | ||
| for (int value : values) { | ||
| result += value; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
Comment on lines
+7
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 코드에서 이 메서드의 역할은 리스트의 값을 모두 더해 최종 합계를 반환하는 것 같아요! 😄
반면, 이 메서드는 결국 // total을 만드는 과정이 sum
for (int value : values) {
total += value; // add
}
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 덧셈이니 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package calculator.model; | ||
|
|
||
| import static calculator.model.DelimiterConstants.DEFAULT_DELIMITER_REGEX; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public enum Delimiter { | ||
| COMMA(",", true), | ||
| COLON(":", true), | ||
| DOUBLE_SLASH("//", false), | ||
| NEW_LINE("\\n", false), | ||
| NUMBER("[0-9]+", false), | ||
| SPACE(" ", false); | ||
|
|
||
|
|
||
| private final String delimiter; | ||
| private final boolean isDefault; | ||
|
Comment on lines
+8
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. COMMA, COLON과 안되는 것을 구분하기 위해, isDefault 필드를 가지게 되었고, 더 복잡해진 것 같아요.
기본 구분자 열거형, 커스텀 구분자로 사용할 수 없는 구분자 열거형 이런 식으로 각 책임에 맞게 열거형을 선언하는 것은 어떨까요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delimiter를 통합적으로 사용한 것은 커스텀 구분자에 사용할 수 없는 구분자로 정의하기 위함이 우선적이었습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생각의 변화 유무의 상관 없이 |
||
|
|
||
| Delimiter(final String delimiter, final boolean isDefault) { | ||
| this.delimiter = delimiter; | ||
| this.isDefault = isDefault; | ||
| } | ||
|
|
||
| public static List<String> getDefaultDelimiter() { | ||
| return Stream.of(values()) | ||
| .filter(Delimiter::isDefault) | ||
| .map(Delimiter::getDelimiter) | ||
| .toList(); | ||
| } | ||
|
|
||
| public static boolean isValidDelimiter(String input) { | ||
| return DEFAULT_DELIMITER_REGEX.matcher(input).matches(); | ||
| } | ||
|
|
||
| public static boolean isValidCustomDelimiter(String delimiter) { | ||
| return Stream.of(values()) | ||
| .noneMatch(d -> d.getDelimiter().equals(delimiter)) && !delimiter.matches(NUMBER.getDelimiter()); | ||
| } | ||
|
|
||
| private String getDelimiter() { | ||
| return delimiter; | ||
| } | ||
|
|
||
| private boolean isDefault() { | ||
| return isDefault; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package calculator.model; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| public class DelimiterConstants { | ||
| public static final Pattern DEFAULT_DELIMITER_REGEX = Pattern.compile("^[0-9,:]+$"); | ||
| public static final String CUSTOM_DELIMITER_PREFIX = "//"; | ||
| public static final String CUSTOM_DELIMITER_SUFFIX = "\\n"; | ||
| } | ||
|
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // 1. 이벤트용으로 사용할 상수를 만들 때 상속
class EventDelimiterConstants extends DelimiterConstants {
public static final String EVENT_DELIMITER = "event";
}
// 2. 인스턴스화
DelimiterConstants ds = new DelimiterConstants; // 가능
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
의도하지 않았습니다,,😢 예혁님 말대로 상수 저장을 위한 클래스이기 때문에 인스턴스화 방지를 하는게 맞다고 생각합니다! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package calculator.model; | ||
|
|
||
| import static calculator.model.DelimiterConstants.CUSTOM_DELIMITER_PREFIX; | ||
| import static calculator.model.DelimiterConstants.CUSTOM_DELIMITER_SUFFIX; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class DelimiterExtractor { | ||
|
|
||
| public List<String> extract(final String input) { | ||
| if (isCheckCustomDelimiterFormat(input)) { | ||
| validateCustomDelimiterFormat(input); | ||
| return extractCustomDelimiters(input); | ||
| } | ||
|
|
||
| validateDefaultDelimiter(input); | ||
| return Delimiter.getDefaultDelimiter(); | ||
| } | ||
|
Comment on lines
+10
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드 내에서 줄바꿈을 사용하는 지윤님의 기준을 설명해주실 수 있나요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문맥상 연관이 있다고 생각한 부분을 줄바꿈 없이 작성한 것 같아요. |
||
|
|
||
| private boolean isCheckCustomDelimiterFormat(final String input) { | ||
| return input.startsWith(CUSTOM_DELIMITER_PREFIX) || input.contains(CUSTOM_DELIMITER_SUFFIX); | ||
| } | ||
|
|
||
| private void validateCustomDelimiterFormat(final String input) { | ||
| if (!input.startsWith(CUSTOM_DELIMITER_PREFIX) || !input.contains(CUSTOM_DELIMITER_SUFFIX)) { | ||
| throw new IllegalArgumentException("커스텀 구분자 형식에 맞게 입력해주세요."); | ||
| } | ||
| validateEmptyCustomDelimiter(input); | ||
| } | ||
|
|
||
| private void validateEmptyCustomDelimiter(final String input) { | ||
| int start = CUSTOM_DELIMITER_PREFIX.length(); | ||
| int end = input.indexOf(CUSTOM_DELIMITER_SUFFIX); | ||
|
|
||
| if (end <= start) { | ||
| throw new IllegalArgumentException("커스텀 구분자를 입력해주세요."); | ||
| } | ||
| } | ||
|
|
||
| private List<String> extractCustomDelimiters(String input) { | ||
| List<String> delimiters = List.of( | ||
| input.substring(CUSTOM_DELIMITER_PREFIX.length(), input.indexOf(CUSTOM_DELIMITER_SUFFIX))); | ||
| validateAllCustomDelimiter(delimiters); | ||
|
|
||
| return delimiters; | ||
| } | ||
|
|
||
| private void validateAllCustomDelimiter(List<String> delimiters) { | ||
| for (String delimiter : delimiters) { | ||
| validateCustomDelimiter(delimiter); | ||
| } | ||
| } | ||
|
|
||
| private void validateCustomDelimiter(final String delimiter) { | ||
| if (!Delimiter.isValidCustomDelimiter(delimiter)) { | ||
| throw new IllegalArgumentException("사용 가능한 커스텀 구분자를 입력해주세요."); | ||
| } | ||
| } | ||
|
|
||
| private void validateDefaultDelimiter(final String input) { | ||
| if (!Delimiter.isValidDelimiter(input)) { | ||
| throw new IllegalArgumentException("기본 구분자(,나 :)를 사용해주세요."); | ||
| } | ||
| } | ||
|
Comment on lines
+60
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기본 구분자 정책이
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용자가 예외 메세지를 보고 문제를 파악하는데에 편리해야 한다고 생각해 자세하게 작성해주는 것이 맞다고 생각했어요! 하지만, 예혁님이 말씀해주신 것처럼 변경되었을 때 수정해야한다는 불편함이 있을 수 있겠네요! 고려해서 수정해보겠습니다. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package calculator.model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Parser { | ||
|
|
||
| public static List<Integer> parse(final List<String> input) { | ||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 생각해도 어떤 일을 하는지 명확하게 표현하지 못한 것 같아요! |
||
| try { | ||
| List<Integer> numbers = getNumbers(input); | ||
| for (int number : numbers) { | ||
| validatePositiveNumber(number); | ||
| } | ||
|
|
||
| return numbers; | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("숫자만 입력해주세요."); | ||
| } | ||
| } | ||
|
|
||
| private static List<Integer> getNumbers(final List<String> input) { | ||
| return input.stream() | ||
| .mapToInt(Integer::parseInt) | ||
| .boxed() | ||
| .toList(); | ||
| } | ||
|
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이
제 개인적인 기준으로는 두 가지 책임(변환과 수집)이 포함된 것으로 보이는데,
지윤님의 기준으로 이 메서드는 몇 가지의 책임을 수행하고 있나요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
저는
말씀하신 대로 변환하는 일을 위임했지만 거기서 발생할 수 있는 예외 상황을 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
말씀하신 의도가 메서드의 시그니처로 충분히 설명될 것 같나요? 지윤님의 생각은 어떠신가요? |
||
|
|
||
| private static void validatePositiveNumber(final int number) { | ||
| if (number < 0) { | ||
| throw new IllegalArgumentException("양수를 입력해주세요."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package calculator.model; | ||
|
|
||
| import static calculator.model.DelimiterConstants.CUSTOM_DELIMITER_SUFFIX; | ||
|
|
||
| import java.util.List; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class StringSplitter { | ||
|
|
||
| public List<String> split(String input, final List<String> delimiters) { | ||
| input = preprocessingCustomDelimiter(input); | ||
|
|
||
| String regex = getRegex(delimiters); | ||
| String[] splitResult = input.split(regex); | ||
|
|
||
| return List.of(splitResult); | ||
| } | ||
|
|
||
| private String preprocessingCustomDelimiter(String input) { | ||
| if (input.contains(CUSTOM_DELIMITER_SUFFIX)) { | ||
| input = input.substring(input.indexOf(CUSTOM_DELIMITER_SUFFIX) + 2); | ||
| } | ||
|
|
||
| return input; | ||
| } | ||
|
Comment on lines
+20
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2는 무엇을 의미할까요?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
예를 들어, 입력값이 하지만 |
||
|
|
||
| private String getRegex(final List<String> delimiters) { | ||
| return delimiters.stream() | ||
| .map(Pattern::quote) | ||
| .collect(Collectors.joining("|")); | ||
| } | ||
|
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정규표현식에서 OR을 의미합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 처음보는 개발자가 이해하기 어려울 것 같아요. 상수화를 해보는 것은 어떨까요? |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||
| package calculator.view; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import camp.nextstep.edu.missionutils.Console; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public class InputView { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public static final String START_MESSAGE = "덧셈할 문자열을 입력해주세요."; | ||||||||||||||||||||||||||
| public static final String USAGE_GUIDE = """ | ||||||||||||||||||||||||||
| [사용 안내] | ||||||||||||||||||||||||||
| 기본 구분자 => ,(쉼표)와 :(콜론)만 사용 가능합니다. | ||||||||||||||||||||||||||
| 커스텀 구분자 => //{구분자}\\n 형식을 사용해 선언할 수 있습니다. | ||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||
|
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앞서 가이드 관련 리뷰와 같이 수정이 될 경우 더 빠르게 찾을 수 있다고 생각했습니다. 물론, 안내 문구를 보고 사용 방법을 안내하기 위한 의도인 것을 알 수 있지만, 코드 내에 작성하는 것보다 상수로 관리하여 해당 메세지가 어떤 것을 의미하는 지 더 명확하고 가독성 있을 것이라고 판단하여 상수로 두었습니다! |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private InputView() { | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public static String getInput() { | ||||||||||||||||||||||||||
| System.out.println(START_MESSAGE); | ||||||||||||||||||||||||||
| System.out.println(USAGE_GUIDE); | ||||||||||||||||||||||||||
| return Console.readLine(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package calculator.view; | ||
|
|
||
| public class OutputView { | ||
|
|
||
| private OutputView() { | ||
| } | ||
|
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. View 부분이 간단해 보이는 것 같은데,
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 두 뷰로 나눈 이유는 Input은 입력, Output은 출력을 담당해야 한다고 생각했기 때문입니다. 그렇다면 간단한 출력일 경우에는 그냥 View를 담당하는 클래스 하나에 모아두는 것이 더 나을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 입력과 출력을 나눈다고 하셨는데 지윤님이 생각하시는 입력과 출력의 정의는 무엇인가요? // InputView 클래스
public static String getInput() {
System.out.println(START_MESSAGE); // 이것도 출력 아닌가요?
System.out.println(USAGE_GUIDE);
return Console.readLine();
} |
||
|
|
||
| public static void printResult(final int result) { | ||
| System.out.println("결과 : " + result); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커밋 메시지에 관한 지윤님만의 기준(단위 및 시제, 어조 포함)이 있으면 좋을 것 같아요. 😄
커밋은 작성 당시의 변경 사항을 설명하는 게 아니라 왜와 무엇이 바뀌었는지 기록하는 것이다. 라는 기준이 있다고 가정하면,
단순한 서술보다 의도를 명확히 하는 데 중점을 둘 수 있을 것 같아요. (중요한건 일관성!)
커밋 메시지 본문에
판별한다.,판별합니다.,추가하였습니다.시제와 어조가 혼재되어 있어 통일하면 더 좋을 것 같아 리뷰 남깁니다! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}는 무엇을 의미하나요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 차이가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커밋 메세지를 일관적이게 작성했다고 생각했는데 놓친 부분이 있었군요 😅 조금 더 신경써서 작성하겠습니다. 감사합니다 :)
헉 저
{구분자}는 {}를 제외한 구분자만 입력하는 걸 표현한 것이었는데 혼동이 있을 수 있겠네요! 수정하겠습니다.기본 구분자 사이의 공백을 제대로 처리하지 못하고 있는 것 같아요 🥺 수정하겠습니다!