Skip to content
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

πŸš€ 1단계 - λ¬Έμžμ—΄ λ§μ…ˆ 계산기 #1069

Open
wants to merge 15 commits into
base: aimbe
Choose a base branch
from

Conversation

Aimbe
Copy link

@Aimbe Aimbe commented Nov 25, 2024

μ•ˆλ…•ν•˜μ„Έμš” κ²½λ‘λ‹˜ !οΏ½step1은 객체의 μ±…μž„μ„ λΆ„λ¦¬ν•˜λ €κ³  쀑점을 λ’€μŠ΅λ‹ˆλ‹€!
이번 λ―Έμ…˜ 잘 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€!

Copy link

@Rok93 Rok93 left a comment

Choose a reason for hiding this comment

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

μ •ν˜Έλ‹˜ μ•ˆλ…•ν•˜μ„Έμš”.
둜또 λ―Έμ…˜μ„ ν•¨κ»˜ν•˜κ²Œλœ κΉ€κ²½λ‘μž…λ‹ˆλ‹€. πŸ€—

1단계 κ΅¬ν˜„ μž˜ν•΄μ£Όμ…¨μŠ΅λ‹ˆλ‹€. πŸ‘πŸ‘
λͺ‡λͺ‡ μ½”λ©˜νŠΈ λ‚¨κ²¨λ‘μ—ˆμœΌλ‹ˆ ν™•μΈν•΄μ„œ 반영 λΆ€νƒλ“œλ¦΄κ²Œμš”. πŸ™
λ―Έμ…˜ μ§„ν–‰ν•˜μ‹œλ©΄μ„œ μ–΄λ €μš΄λΆ€λΆ„ 생기면 μ–Έμ œλ“ μ§€ DM μ£Όμ„Έμš”. 😁

#### κΈ°λŠ₯ μš”κ΅¬μ‚¬ν•­

- [ ] κΈ°λ³Έ κ΅¬λΆ„μžλ₯Ό μ΄μš©ν•œ λ¬Έμžμ—΄ 뢄리 및 λ§μ…ˆ
Copy link

Choose a reason for hiding this comment

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

κΈ°λŠ₯ κ΅¬ν˜„ λͺ©λ‘ν‘œλ₯Ό μž‘μ„± πŸ‘πŸ’―

ν•΄λ‹Ή κΈ°λŠ₯이 κ΅¬ν˜„λ˜λ©΄ κΈ°λŠ₯ κ΅¬ν˜„ λͺ©λ‘ν‘œλ„ 같이 μ—…λ°μ΄νŠΈν•΄μ„œ μ»€λ°‹ν•˜λ©΄ 쑰금 더 μ‚΄μ•„μžˆλŠ” λ¬Έμ„œκ°€λ  것 κ°™μ•„μš”. πŸ€—

Copy link
Author

Choose a reason for hiding this comment

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

μ•— μš”κ΅¬ λͺ…μ„Έλ₯Ό μ—…λ°μ΄νŠΈ ν•˜λŠ”κ²ƒμ„ κΉœλΉ‘ν–ˆλ„€μš”! γ…‹γ…‹ μ²΄ν¬ν•˜κ² μŠ΅λ‹ˆλ‹€ κ°μ‚¬ν•©λ‹ˆλ‹€!

@@ -0,0 +1,6 @@
package calculator

interface DelimiterStrategy {
Copy link

Choose a reason for hiding this comment

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

였.. μ „λž΅ νŒ¨ν„΄μ„ ν™œμš©ν•˜μ—¬ κΈ°λ³Έ κ΅¬λΆ„μž(μ‰Όν‘œ, 콜둠)와 μ»€μŠ€ν…€ κ΅¬λΆ„μžλ₯Ό κ΅¬ν˜„ν•˜μ…¨κ΅°μš”? πŸ‘πŸ’―
μΆ”ν›„ μƒˆλ‘œμš΄ κ΅¬λΆ„μž 정책이 생기더라도 Strategyλ₯Ό ν•˜λ‚˜ 더 κ΅¬ν˜„ν•΄μ£ΌκΈ°λ§Œν•˜λ©΄ μ‰½κ²Œ λŒ€μ‘ν•  수 μžˆκ² κ΅°μš”? πŸ˜ƒ


class CustomDelimiterStrategy : DelimiterStrategy {
override fun supports(text: String): Boolean {
return text.startsWith("//") && text.contains("\n")
Copy link

Choose a reason for hiding this comment

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

음.. 이 뢀뢄은 μ˜λ„μ™€ 달리 λ™μž‘ν•  수 μžˆλŠ” 여지가 μžˆμ–΄λ³΄μž…λ‹ˆλ‹€. πŸ€”
이 μΌ€μ΄μŠ€λŠ” κ°€λŠ₯ν•˜λ©΄ μ •κ·œμ‹μ„ ν™œμš©ν•΄λ³΄λ©΄ μ–΄λ–¨κΉŒμš”? πŸ˜ƒ

λ―Έμ…˜ μ†Œκ°œ νŽ˜μ΄μ§€μ—μ„œλŠ” μ»€μŠ€ν…€ κ΅¬λΆ„μžλ₯Ό μ•„λž˜μ™€ 같이 μ •μ˜ν•˜κ³ μžˆμ–΄μš”.

μ»€μŠ€ν…€ κ΅¬λΆ„μžλŠ” λ¬Έμžμ—΄ μ•žλΆ€λΆ„μ˜ β€œ//”와 β€œ\n” 사이에 μœ„μΉ˜ν•˜λŠ” 문자
1κΈ€μžλΌκ³  λͺ…μ‹œν•œ 것은 μ•„λ‹ˆμ§€λ§Œ, λ¬ΈμžλΌκ±°λ‚˜ 예제의 μΌ€μ΄μŠ€λ₯Ό μƒκ°ν–ˆμ„ λ•Œ, ν•œ κΈ€μžκ°€ μ•„λ‹Œκ°€ μ‹Άμ–΄μš”.

  • λ―Έμ…˜ μ†Œκ°œ νŽ˜μ΄μ§€μ˜ μž…λ ₯ 예제: //;\n1;2;3
  • 였λ₯˜κ°€ λ‚  수 μžˆλŠ” μΌ€μ΄μŠ€1: '//;;\n1;2;3'
  • 였λ₯˜κ°€ λ‚  수 μžˆλŠ” μΌ€μ΄μŠ€1: '//1;2;3\n'

Copy link
Author

Choose a reason for hiding this comment

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

저도 사싀 κ΅¬ν˜„ν•˜λ©΄μ„œ μ˜ˆμ™Έμ μΈ μΌ€μ΄μŠ€μ— λ™μž‘μ„ μ•ˆν•˜κ² λŠ”λ°..? 생각을 ν•˜λ‹€κ°€
μ£Όμš” κ΅¬ν˜„ λͺ©ν‘œκ°€ TDD라 작고 신경을 λœμΌλ˜κ²ƒ κ°™μŠ΅λ‹ˆλ‹€ γ…‹γ…‹ μ •κ·œμ‹ ν™œμš©ν•΄μ„œ ν•œλ²ˆ μ§„ν–‰ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€!

Comment on lines 9 to 10
val delimiter = text.substring(2, 3)
return text.substring(4)
Copy link

Choose a reason for hiding this comment

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

이 μ½”λ“œλ₯Ό μ²˜μŒλ³΄λŠ” μ‚¬λžŒμ΄λΌλ©΄ 2, 3, 4와 같은 μˆ«μžκ°€ μ–΄λ–€ 의미λ₯Ό κ°€μ§€λŠ”μ§€ μ΄ν•΄ν•˜κΈ°κ°€ μ–΄λ €μšΈ 것 κ°™μ•„μš”. πŸ€”
μ•„λž˜μ˜ 글을 μ°Έκ³ ν•΄λ³΄μ‹œλ©΄ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€. πŸ˜ƒ

μ˜λ―Έκ°€ λΆˆλΆ„λͺ…ν•œ 맀직 λ„˜λ²„λ₯Ό μƒμˆ˜λ‘œ μ„ μ–Έν•˜λΌ

Copy link
Author

Choose a reason for hiding this comment

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

λ„΅ constant클래슀 λ§Œλ“€μ–΄μ„œ οΏ½λ§€μ§λ„˜λ²„ μƒμˆ˜ν™” ν–ˆμŠ΅λ‹ˆλ‹€!

}

override fun parse(text: String): List<Int> {
return text.split("[,:]".toRegex())
Copy link

Choose a reason for hiding this comment

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

Patternκ³Ό 같은 λΉ„μ‹Ό 객체의 생성을 λ§€λ²ˆν•  ν•„μš” 없이 μƒμˆ˜λ‘œ 미리 μ •μ˜ν•΄λ‘κ³  μž¬μ‚¬μš©ν•˜λ©΄ μ–΄λ–¨κΉŒμš”? πŸ˜ƒ

객체의 생성과 파괴 - λΆˆν•„μš”ν•œ 객체 생성을 ν”Όν•˜λΌ

Copy link
Author

Choose a reason for hiding this comment

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

였 κ°μ‚¬ν•©λ‹ˆλ‹€! γ…Žγ…Ž μ°Έκ³ ν•˜κ² μŠ΅λ‹ˆλ‹€

DefaultDelimiterStrategy()
)

fun parse(text: String): List<Int> {
Copy link

Choose a reason for hiding this comment

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

λ©”μ„œλ“œ νŒŒλΌλ―Έν„° 이름을 쑰금 더 의미있게 변경해보면 μ–΄λ–¨κΉŒμš”? πŸ€”
λ¬Έμžμ—΄ λ§μ…ˆ κ³„μ‚°κΈ°λΌλŠ” λ„λ©”μΈμ—μ„œ μž…λ ₯ λ°›λŠ” 값은 λ¬΄μ—‡μΈκ°€μš”? κ·Έ μ˜λ―Έκ°€ λ“œλŸ¬λ‚˜λŠ” 넀이밍이면 쒋을 것 κ°™μ•„μš”.

DefaultDelimiterStrategy()
)

fun parse(text: String): List<Int> {
Copy link

Choose a reason for hiding this comment

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

parse λ©”μ„œλ“œμ— λŒ€ν•œ ν…ŒμŠ€νŠΈλ„ μž‘μ„±ν•΄λ³΄μ‹œλ©΄ μ–΄λ–¨κΉŒμš”? πŸ˜ƒ

Comment on lines 10 to 13
return when {
text.length == 1 -> listOf(text.toInt())
else -> parseWithStrategy(text)
}
Copy link

Choose a reason for hiding this comment

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

text의 길이둜만 caseλ₯Ό κ΅¬λΆ„ν•˜μ‹€κ±°λΌλ©΄ μ•„λž˜μ™€ 같이 λ³€κ²½ν•  μˆ˜λ„ μžˆμ„ 것 κ°™λ„€μš”. πŸ˜ƒ

Suggested change
return when {
text.length == 1 -> listOf(text.toInt())
else -> parseWithStrategy(text)
}
return when (text.length) {
1 -> listOf(text.toInt())
else -> parseWithStrategy(text)
}

Copy link
Author

Choose a reason for hiding this comment

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

μ •κ·œμ‹μœΌλ‘œ νŒλ‹¨ 둜직 λ³€κ²½ν•˜λ©΄μ„œ ν•΄λ‹Ή λ‘œμ§λ“€μ€ μ—†μ–΄μ‘Œμ§€λ§Œ, μΆ”ν›„ μ €λŸ° μΌ€μ΄μŠ€ 있으면 μ €λŸ°μ‹μœΌλ‘œ μ“°λŠ”κ²Œ 가독성 더 μ’‹μ•„λ³΄μ΄λ„€μš” γ…Žγ…Ž κ°μ‚¬ν•©λ‹ˆλ‹€~


fun parse(text: String): List<Int> {
return when {
text.length == 1 -> listOf(text.toInt())
Copy link

Choose a reason for hiding this comment

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

text.length == 1의 κ²½μš°μ—λ§Œ ν•˜λ‚˜μ˜ 숫자만 μΆ”μΆœν•˜λŠ”κ±°κ΅°μš”? πŸ€”

λ§Œμ•½ textκ°€ "11"와 같이 λ‘μžλ¦¬ μˆ«μžκ°€ λ“€μ–΄μ˜€κ²Œλ˜λ©΄ μ–΄λ–»κ²Œ λ˜λŠ”κ±ΈκΉŒμš”?

@@ -0,0 +1,12 @@
package calculator

class NumberValidator {
Copy link

Choose a reason for hiding this comment

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

μ§€κΈˆμ²˜λŸΌ λ¬Έμžμ—΄ λ§μ…ˆ κ³„μ‚°κΈ°λΌλŠ” 도메인에 ν•„μš”ν•œ Number 도메인 λͺ¨λΈμ€ 일반적인 Numberλž‘ 달리 μ–‘μˆ˜μ—¬μ•Όν•˜λŠ” νŠΉμ§•μ΄ μžˆλŠ”λ°μš”.
μ›μ‹œ κ°’μœΌλ‘œλŠ” 이런 값을 ν‘œν˜„ν•˜λŠ”λ°μ—λŠ” ν•œκ³„κ°€ μžˆλŠ”λ°μš”. πŸ₯²

μ›μ‹œκ°’μ„ 포μž₯ν•¨μœΌλ‘œμ¨ 도메인에 νŠΉν™”λœ 도메인 λͺ¨λΈμ„ 직접 λ§Œλ“€μ–΄λ³΄μ‹œλ©΄ μ–΄λ–¨κΉŒμš”? πŸ˜ƒ

Copy link
Author

Choose a reason for hiding this comment

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

λ„΅ Numbers 도메인 λͺ¨λΈμ— λŒ€ν•œ 일급 μ»¬λ ‰μ…˜ 생성 λ’€ μ±…μž„ λΆ„λ¦¬ν–ˆμŠ΅λ‹ˆλ‹€!

@Aimbe Aimbe requested a review from Rok93 November 28, 2024 04:09
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