zokipirlo
11/24/2023, 10:26 AMSealedClass.InnerClass syntax?
For example:
sealed class Message(val...) {
class Text(...) : Message(...) {
...
}
class Image(...) : Message(...) {
...
}
}
when (message) {
is Message.Text -> ...
is Message.Image -> ...
}
fun someFun(val msg: Message.Text) {}
But if I extract Text and Image to separete file from Message class file, because that file can be easiliy thounds of lines of code long, it would become:
when (message) {
is Text -> ...
is Image -> ...
}
fun someFun(val msg: Text) {}
And when using those classes all around a project you lose hierarchy that Text is part of Message. I think it's still more pretty to use Message.Text . Could be possible somehow to combine best of both worlds?hfhbd
11/24/2023, 10:31 AMzokipirlo
11/24/2023, 12:18 PMWesley Hartford
11/24/2023, 3:55 PMMessage in the example case). Is that right?
I don't think that's currently possible, but in theory I like the idea. In a lot of cases, it makes sense to use a sealed child class with a qualified syntax such as Message.Text, but if there are a whole lot of sub-classes, the file declaring them all could get unpleasantly large.zokipirlo
11/24/2023, 8:14 PMzokipirlo
11/24/2023, 8:17 PMsealed class but implement them in separate file.stantronic
11/27/2023, 11:28 AMclass Parent.Child()