https://kotlinlang.org logo
Title
t

thana

04/17/2019, 6:19 AM
i have a sealed class with about 10 subclasses (and growing). now i need to map them to a frontend model. so i end up with a huge
when
statement which is more or less unreadibl. so again i end up with a visitor for this class. how do you handle this situation?
mmh ok at least implementing the visiotr is slightly more easy with a
sealed class
k

karelpeeters

04/17/2019, 7:29 AM
You could add an abstract method to the sealed class.
s

streetsofboston

04/17/2019, 11:40 AM
I don't know your exact use-case, but you can subclass a sealed class with other sealed classes. This could allow you to create (sub)categories of your data.
t

thana

04/17/2019, 11:46 AM
yeah in fact i did excactly that . in the end i was trying to find out how other people handle this situation
i mean sealed classes are cool and the exhaustiveness check of the compiler is cool, too. but in the end the visitor pattern still rules... i think
k

karelpeeters

04/17/2019, 2:18 PM
Or just normal polymorphism?