-
Notifications
You must be signed in to change notification settings - Fork 132
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
[문자열 덧셈 계산기] 강유리 미션 제출합니다. #117
base: main
Are you sure you want to change the base?
[문자열 덧셈 계산기] 강유리 미션 제출합니다. #117
Conversation
- 사용자에게 문자열을 입력받는다.
- 입력된 문자열에서 구분자 "," ":"가 있는지 확인한다.
- 구분자 또는 숫자가 아닌 문자가 입력된 경우 예외처리를 진행한다.
- 입력받은 문자열에서 숫자와 구분자를 분리한다. - 숫자의 경우 모두 더한 후 출력한다.
- 발생 가능한 에러 메시지를 object로 관리한다.
- 커스텀 구분자를 인식하고 구분자들을 기준으로 숫자들을 더한다.
- 출력 형식에 맞추어 결과를 출력한다.
- 정규식 패턴을 이용해 문자열 나누는 방식으로 수정한다.
- 변수명 변경 및 가독성을 위한 리팩토링을 진행한다.
- 조건문(if) 대신 takeIf을 활용한다.
- 음수가 입력된 경우의 예외처리를 추가한다.
- 기존 Application.kt 내의 로직을 개별 클래스들로 분리하여 모듈화 하였습니다.
- 구현한 내용을 바탕으로 에러 메시지 설명과 각 파일의 기능을 추가했습니다.
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.
1주차 수고 많으셨어용!! 클래스가 잘 분리되어 있어서 읽으면서 정말 잘 읽히는 코드였어욤!! 많이 배우고 갑니당🍀
private val separatorHandler = Separator() | ||
private val calculatorHandler = Calculator() | ||
|
||
fun run() { |
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.
스코프 함수 중에 'run'이 있기도 하고 정확히 어떤 것을 실행하는 함수인지 명시해주는게 어떨까요?
object ErrorMessages { | ||
const val CUSTOM_SEPARATOR_NOT_PROVIDED = "커스텀 구분자가 입력되지 않았습니다." | ||
const val INVALID_CUSTOM_FORMAT = "커스텀 구분자의 형식이 잘못되었습니다." | ||
const val NUMBER_NOT_PROVIDED = "구분자 사이에 숫자가 없습니다. 계산할 숫자를 입력해주세요." | ||
const val INVALID_NEGATIVE = "음수는 계산할 수 없습니다." | ||
const val INVALID_CHARACTER = "잘못된 입력입니다. 숫자나 구분자가 아닌 값이 포함되었습니다" | ||
} |
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.
와.. 이렇게 에러메세지만 따로 관리하는게 너무 좋은 것 같아요!!👍🏻
val suffixIndex = parsedInput.indexOf(CUSTOM_SUFFIX) | ||
val customSeparator = parsedInput.substring(prefixIndex, suffixIndex) | ||
|
||
customSeparator.takeIf { it.isNotEmpty() } |
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.
takeif를 사용해본 적은 없는데 이렇게 null을 다룰 때 사용하니 가독성 측면에서 좋은 것 같아욤!!
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.
고생하셨습니다~! 구경하다 느낀 점들을 리뷰로 남겨봅니다!
|
||
class Calculator { | ||
|
||
fun calculateSum(parsedInput: String, separatorList: MutableList<String>): Int { |
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.
파라미터로 MutableList를 받을 필요가 있을까요?
|
||
fun calculateSum(parsedInput: String, separatorList: MutableList<String>): Int { | ||
val separatorPattern = separatorList.joinToString("|") { Regex.escape(it) } | ||
val numbers = parsedInput.split(Regex(separatorPattern)) |
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.
이 numbers
라는 변수명만 보면 숫자의 List
일 것 같지만, 실제로는 String
의 List
인 것 같아요.
명시적으로 String의 List임을 알려주는 것이 좋아 보입니다!
number.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException(ErrorMessages.NUMBER_NOT_PROVIDED) | ||
number.takeIf { it >= "0" } ?: throw IllegalArgumentException(ErrorMessages.INVALID_NEGATIVE) | ||
sum += number.toIntOrNull() ?: throw IllegalArgumentException(ErrorMessages.INVALID_CHARACTER) |
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.
해당 구문은 각 number가 올바른지 검증하는 로직인 것 같아요. 해당 책임을 Calculator에서 담당하는 것이 좋은 방식일까요??
private val inputHandler = Input() | ||
private val outputHandler = Output() | ||
private val separatorHandler = Separator() | ||
private val calculatorHandler = Calculator() |
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.
CalculatorApp이 너무 다양한 클래스에 의존하고 있는 것 같아요. 이렇게 될 경우 모든 클래스의 변경에 취약해지기도 하고, 테스트에도 어려움이 있을 것 같은데, 이를 어떻게 개선하는 것이 좋을까요?
if (originInput.isBlank()) { | ||
outputHandler.printCalculateResult(0) | ||
return | ||
} |
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.
이 로직은 입력된 값에 대한 처리인 것 같습니다. 입력된 값에 대한 처리를 할 때엔 어느 클래스에서 하는 것이 좋을까요?
안드로이드에서는 TextField를 통해 입력된 값에 대한 처리를 어디서 담당하나요?
} | ||
} | ||
|
||
return Pair(parsedInput, separators) |
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.
return Pair(parsedInput, separators) | |
return parsedInput to separators |
to
연산자를 사용해볼 수도 있을 것 같아요!
구현 기능
1주차 미션, 입력한 문자열에서 숫자를 추출하여 더하는 계산기를 구현하였습니다.
commit message convetion
1주차 미션 커밋 컨벤션은 다음과 같습니다.
커밋태그(변경된 파일명): 구현한 기능 또는 커밋의 주제 작성