louiscad
09/24/2021, 9:56 AMsealed interface
or sealed class
.
What would you pick? Any reason beyond personal preference?
1️⃣ Here's with `interface`:
sealed interface AudioFocus {
object Gain : AudioFocus
sealed interface Loss : AudioFocus {
companion object : Loss
sealed interface Transient : Loss {
companion object : Transient
object CanDuck : Transient
}
}
}
2️⃣ Here's with `class`:
sealed class AudioFocus {
object Gain : AudioFocus()
sealed class Loss : AudioFocus() {
companion object : Loss()
sealed class Transient : Loss() {
companion object : Transient()
object CanDuck : Transient()
}
}
}
Javier
09/24/2021, 9:57 AMephemient
09/24/2021, 4:53 PMcompanion object
here will look nice with AudioFocus.Loss
being usable as a value, I think it's awkward that its type is actually AudioFocus.Loss.Companion
.Zach Klippenstein (he/him) [MOD]
09/24/2021, 5:30 PMephemient
09/25/2021, 12:16 AMinterface
louiscad
09/28/2021, 7:15 AMsealed interface
(Java compatibility isn't a concern in my case).
Here's a full gist that includes a suspend-first API to work with AudioFocus on all Android versions:
https://gist.github.com/LouisCAD/4ca4bd6cb85e3d8b2509492d67b282f7