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

[둘리] 2단계 자동차 경주 제출합니다. #68

Merged
merged 12 commits into from
Feb 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor(CarsHelper): companion object를 object로 수정
  • Loading branch information
hyemdooly committed Feb 12, 2023
commit 3e97c71647b06615b9fc63a2adf6fe680e8a2ce1
12 changes: 5 additions & 7 deletions src/main/kotlin/util/CarsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package util

import model.Cars

class CarsHelper {
companion object {
fun findWinners(cars: Cars): List<String> {
val carInfos = cars.getCarInfos()
val equalCars = carInfos.groupBy({ it.position }, { it.name })
return equalCars[equalCars.keys.max()]?.toList() ?: listOf()
}
object CarsHelper {

Choose a reason for hiding this comment

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

객체 이름만 봤을 때는 "자동차들의 도우미"로 해석이 되는데요.
여기서 Helper라는 단어는 포괄적인 의미로 사용돼요.
클래스에 정의된 함수의 역할에 맞게 클래스명을 작성해보면 어떨까요?

fun findWinners(cars: Cars): List<String> {
val carInfos = cars.getCarInfos()
val equalCars = carInfos.groupBy({ it.position }, { it.name })
return equalCars[equalCars.keys.max()]?.toList() ?: listOf()

Choose a reason for hiding this comment

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

방어적 복사 활용 👍
추가로 빈 리스트를 리턴하고 싶으시다면, listOf()보다는 emptyList()가 좀 더 가독성이 좋습니다.

}
}