https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
c

Cicero

09/06/2021, 12:31 PM
Hey, how do you make proper distribution of your data layer objects and why wouldn't you do something like this (code in the thread)
Copy code
sealed interface IExercise {
    val id: Int
}

sealed class Exercise {
    @Serializable
    data class Remote(
        override val id: Int,
    ) : IExercise {
        fun toCacheEntity() = DB(
            id = id,
        )
    }

    data class Model(
        val isFavorite: Boolean,
        override val id: Int,
    ) : IExercise {
        fun toRemote() = Remote(
            id = id,
        )
    }
    data class DB(
        override val id: Int,
    ) : IExercise, RealmObject() {
        fun toModel(isFavorite: Boolean = false) = Model(
            id = id, isFavorite = isFavorite,
        )
    }
}
Well, realm doesn't support nested classes and this wont work but I'm still curious if someone is doing something that will not end with 3 different folders with their individual classes and methods where I could use a more intelligent syntax
u

ursus

09/11/2021, 1:31 AM
Whats the reason for the sealed class? Feels like wrong axis to me test
c

Cicero

09/11/2021, 10:08 AM
Excuse me for that, that is totally wrong. But even without that Realm doesn't allow its data classes to be inner classes
And for some reason I can edit this on my mobile device. The F.
Ok, you can't edit messages in this channel
u

ursus

09/11/2021, 8:07 PM
i can
c

Cicero

09/11/2021, 8:15 PM
:| I'm being repressed 😂
Anyway it wouldn't work even without the sealed tag. But I wish I could have something like this. I'm already using this for my regular objects
5 Views