Alejo
03/23/2022, 8:25 PM@Parcelize
data class Order(val fees:List<Fee>, total:Double): Parcelable
@Parcelize
data class Fee(val amount:Double): Parcelable
But now I need another type of Fee, a percentage fee, and I would love some ideas on tackling this problem.
My first thought was to use hierarchy to help me with this, something like:
@Parcelize
data class Order(val fees:List<IFee>, total:Double): Parcelable
interface IFee {
fun getTotalFee(): Double
}
@Parcelize
data class AmountFee(val amount: Double) : IFee, Parcelable {
override fun getTotalFee() = amount
}
@Parcelize
data class PercentageFee(
val orderTotal:Double,
val percentage: Double
) : IFee, Parcelable {
override fun getTotalFee() = (percentage * orderTotal) / 100
}
Until Parcelize started complaining about the interface.
I'm not sure if there is a better approach so wanted to check before further working on this solution because Parcelize and data class can be tricky with hierarchy.
Any help is appreciated 😁
Thanks in advanced