<https://kotlinlang.org/docs/sealed-classes.html#c...
# getting-started
a
https://kotlinlang.org/docs/sealed-classes.html#constructors these two code styles have the same result. why is white picture's code style better than black picture's one?
h
Please make it clear, what part exactly do you mean. I guess the sealed class: It just act like namespace when putting the definition of the classes into the body of the
Error
class so you don't clutter your package namespace with classes related to
Error
. BTW if the class holds no state, you could also use a
data object
instead.
a
docs by itself, have two code styles. I am very crazy.
j
A class can be at the top level or nested inside another class. If it's nested, its name is different: its fully qualified name includes the name of the containing class. Usually, we refer to nested classes using
Containing.Nested
so nesting a class is just a different way to namespace it. Sometimes it makes more sense this way, it depends on the case.
a
so it have no little benefits, only personal taste, right?
j
We can consider it taste, but it changes a little bit the experience. For instance, you can have auto-completion in the IDE more easily if you type the containing class name, then a dot
g
It's not about taste, it depends on different use cases, would you like to group them or not and what kind of name you would like for this case, practice shows that both styles used side by side
1