내가 다른 캐럿 파일에있는 세 개의 클래스가 있습니다 https://github.com/antoniolg/Kotlin-for-Android-DevelopersKotlin에서 중복 클래스를 줄이기 위해 설계하는 방법은 무엇입니까?
에서 "안드로이드 개발자 (책)에 대한 코 틀린"샘플을 배우고, 나는 세 가지 클래스가 비슷 생각하고, 이러한 mulit 클래스는 프로그램 복잡합니다.
어떻게 프로젝트 프레임 워크를 재 설계하고 프로젝트를보다 명확하게 만들 수 있습니까?
DbClasses.kt
class DayForecast(var map: MutableMap<String, Any?>) {
var _id: Long by map
var date: Long by map
var description: String by map
var high: Int by map
var low: Int by map
var iconUrl: String by map
var cityId: Long by map
constructor(date: Long, description: String, high: Int, low: Int, iconUrl: String, cityId: Long)
: this(HashMap()) {
this.date = date
this.description = description
this.high = high
this.low = low
this.iconUrl = iconUrl
this.cityId = cityId
}
}
데이터베이스의 관점에서 tables.kt
object DayForecastTable {
val NAME = "DayForecast"
val ID = "_id"
val DATE = "date"
val DESCRIPTION = "description"
val HIGH = "high"
val LOW = "low"
val ICON_URL = "iconUrl"
val CITY_ID = "cityId"
}
DomainClasses.kt
data class Forecast(
val id: Long,
val date: Long,
val description: String,
val high: Int,
val low: Int,
val iconUrl: String
)