Which is the better approach for `name`? ```sealed...
# codingconventions
d
Which is the better approach for
name
?
Copy code
sealed class Things {
    abstract val name: String

    data class ThingA(val x: Int, val y: String) : Things() {
        override val name = "foo"
    }

    data class ThingB(z: Double) : Things() {
        override val name = "bar"
    }
}
or
Copy code
sealed class Things(val name: String) {
    data class ThingA(val x: Int, val y: String) : Things("foo")

    data class ThingB(z: Double) : Things("bar")
}
2️⃣ 1
m
I'd go with 2 for a number of reasons. The second tells me at a glance that all Things have a
name
, and it's also less code to read.
1
t
I prefer 2 also. We’ve done 1) and I’ve found it quite difficult to follow
d
Makes sense. Thanks for the input!