In my Kotlin application, I deal with some membership types. For example:
interface MembershipType {
fun getExcessOptions(): List
}
The derived types are GOLD
, SILVER
, BRONZE
, PLATNIUM
All 4 types have list of excess options. For example:
enum class MembershipType(val name: String) : IValueOptions {
SILVER("silver") {
override fun getExcessOptions() = listOf(300,200,100)
}, //for GOLD, BRONZE, PLATNIUM etc
For GOLD
and SILVER
types, they can be selected as a Bundle
and so they must have list of pre-defined valueOptions
which one can pick from.
For BRONZE
, PLATNIUM
, they can only be Named
, so user inputs their own value, they have a choice..
Basically I want to represent the following:
MemeberShip Type || Options || Value Options
GOLD || Bundle || 100, 200, 3000
SILVER || Bundle and Named || 4000, 5000
PLATINUM || Named
BRONZE || Named
data class Bundle (
val excess: Int
val value: Int
)
data class Named (
val excess: Int
val value: Int
)
How can I represent this in terms of classes and inheritence in Kotlin or even as enums as two of the types are unique in the sense they have pre-defined valueOptions
property?
Aucun commentaire:
Enregistrer un commentaire