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
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
refactor(Car,Cars): backing property 수정
  • Loading branch information
hyemdooly committed Feb 13, 2023
commit affbefb440fb3e8f3473f5a8e54362ff727411a0
10 changes: 4 additions & 6 deletions src/main/kotlin/model/Car.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package model

import util.Validator

class Car(private val _name: String, private var _position: Int = 0) {
class Car(val name: String, position: Int = 0) {

val name: String
get() = _name
val position: Int
get() = _position
private var _position: Int = position
val position: Int get() = _position

init {
Validator().checkName(_name)
Validator().checkName(name)
}

fun move(condition: Int) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/model/Cars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package model

import generator.RandomGenerator

class Cars(private val _cars: List<Car>) {
val cars: List<Car>
get() = _cars
class Cars(cars: List<Car>) {
private val _cars: List<Car> = cars
val cars: List<Car> get() = _cars

Choose a reason for hiding this comment

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

Suggested change
class Cars(cars: List<Car>) {
private val _cars: List<Car> = cars
val cars: List<Car> get() = _cars
class Cars(val cars: List<Car>) {

Cars 클래스에는 add를 하는 로직이 없습니다.
그렇다면 굳이 backing property 구조로 작성할 필요가 없어 보이네요.


constructor(input: String) : this(input.split(",").mapIndexed { _, name -> Car(name.trim()) })

Expand Down