I want to model a multi-dimensional hierarchy of s...
# getting-started
I want to model a multi-dimensional hierarchy of status codes: I have different operations like "generate data" or "upload file", and for each of them I have either "success" or "failure". All "failure" should carry a message, and groups like "generate" or "upload" also share some attributes. The existing code uses an enum for the different status codes and then a bunch of nullable properties for the different properties (nullable because they are sparsely filled/used). A better way seems to be a sealed class hierarchy. But modelling this straight forward would require multi-inheritance. Is there a good way to model this?
Copy code
sealed interface Status
sealed class Failure(val message: String) : Status
sealed class Upload(val name: String) : Status
sealed class UploadFailure(message: String, name: String) : Failure(message), Upload(name)
likely cleanest to pick one dimension for the classes, say “operation”, and have status as an attribute thereof.
Could you achieve what you want by replacing some of the sealed classes with sealed interfaces?
Copy code
sealed interface Status
sealed interface Failure: Status {
    val message: String
sealed interface Upload {
    val name: String
data class UploadFailure(
    override val message: String,
    override val name: String
): Upload, Failure
🙌 1
Will try the suggestions and then revert back here with my choice
thanks for the suggestions