Currently I have three enum classes that represents states in my state machine and one to display operations
interface State
enum class OperationState : State {
InProgress,
Finished,
Error
}
enum class FirstState : State {
//some states
}
enum class NextState: State {
//some states
}
enum class LastState: State {
//some states
}
In my service I have:
when (state) {
is FirstState -> {
//do something
changeFirstStateOperationState(state)
}
is NextState -> {
//do something
changeNextStateOperationState(state)
}
is LastState -> {
//do something
changeLastStateOperationState(state)
}
}
private fun changeFirstStateOperationState(state: FirstState){
when(state){
FirstState.A -> OperationState.Error
listOf(FirstState.B, FirstState.C) -> OperationState.InProgress
FirstState.D -> OperationState.Finished
}
}
I would like change my current implmenetation to sealed classes. I tried something like:
sealed class State {
sealed class OperationState : State() {
sealed class FirstState : OperationState() {
object A: FirstState()
object B: FirstState()
object C: FirstState()
object D: FirstState()
}
sealed class NextState:OperationState(){ ... }
sealed class LastState:OperationState(){ ... }
}
}
but it doesn't work...
Is there any way, using the sealed class, to know what is current OperationStatus without mapping State to it?