Is it possible to extend an existing Kotlin class to conform to a interface?
Copy code
data class MediaItem(
override val title: String,
override val artist: String?
)
Copy code
interface MediaItemProtocol {
val title: String
val artist: String?
Copy code
extend AstroMediaItem: MediaItemProtocol {
}
markturnip
07/08/2024, 12:42 AM
this sort of thing is possible in swift, such as:
Copy code
extension MediaItem: MediaItemProtocol {
}
e
ephemient
07/08/2024, 12:47 AM
no, extension interfaces are not possible
m
markturnip
07/08/2024, 1:46 AM
so with a modular approach where by a model definition is in one package and protocol in another, that means having a third definition to bind the two?
Copy code
class MediaItemWrapper(private val item: MediaItem) : MediaItemProtocol {
override val title: String get() = item.title
override val artist: String? get() = item.artist
}