Hi everyone, I have a short question. I need to cr...
# android
d
Hi everyone, I have a short question. I need to create adapter for recycler view which has many view types, so I'm in a dilemma which approach to take regarding data modelling. Should I use interface or sealed class to model the data for this adapter? Which approach is better, what are the pros and cons?
😶 2
In Java I would have to take the first approach, and go with interfaces.
k
You can also do a sealed interface
d
Of course I didn't mention sealed interfaces. But the question was more like: If I use sealed class I can share some properties between sealed class members. But what would be the cons or pros of this approach against using sealed interface or regular interface?
Pros and cons in terms of later maintainability/scalability?
k
Sealed interfaces/classes are just as maintainable and scalable as a regular interfaces, I'll consider that there are only pros in using them for your specific use case 👉 https://kotlinlang.org/docs/sealed-classes.html
👍 1
1
c
the control you get with sealed is that you indicate that the hierarchy is static, which means things like
when
statements can tell you when you're being exhaustive or not.
👍 1