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
Dragan Vojvodić
11/10/2022, 1:23 PM
In Java I would have to take the first approach, and go with interfaces.
k
Kevin Del Castillo
11/10/2022, 1:49 PM
You can also do a sealed interface
d
Dragan Vojvodić
11/10/2022, 1:53 PM
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?
Dragan Vojvodić
11/10/2022, 1:54 PM
Pros and cons in terms of later maintainability/scalability?
k
Kevin Del Castillo
11/10/2022, 1:54 PM
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
czuckie
11/10/2022, 3:16 PM
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.