2017-11-07 1 views
1

내가 다른 캐럿 파일에있는 세 개의 클래스가 있습니다 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 
) 

답변

1

필드에 주석을 달고 데이터베이스 테이블 스키마 (DayForecastTable에 대한 필요성 제거)를 생성하는 ORM 라이브러리 사용에 대해 생각할 수 있습니다. 방 (https://developer.android.com/training/data-storage/room/index.html)

도메인 클래스를 데이터베이스와 별도로 유지하도록 도메인 계층 클래스를 유지하는 것이 좋지만 전체 앱에서 기술적으로 이러한 클래스를 사용하여 DomainClasses에 대한 필요성을 줄일 수 있습니다.

관련 문제