Closed manueldidonna closed 4 years ago
Many properties have been added from one generation to the next. I don't want to create specific pokemon implementation for each gen.
sealed class Property<out T> { object Nothing: Property<Nothing>() data class Value<T>(val value: T): Property<T>() } inline fun <T> T.asProperty(): Property<T> = Property.Value(this) inline fun <T> Property<T>.valueOrNull(): Property.Value<T>? = this as? Property.Value<T> interface Pokemon { val heldItem: Property<Int> get() = Property.Nothing } internal class Gen2Pokemon: Pokemon { override val heldItem = itemId.asProperty() } // From UI @Composable fun ShowInfo(pokemon: Pokemon) { pokemon.heldItem.valueOrNull()?.let { ShowHeldItem(it.value) } }
Many properties have been added from one generation to the next. I don't want to create specific pokemon implementation for each gen.