Ed Holloway-George
1 min readJan 15, 2021

--

Hi Aaron, thank you for your kind words.

Not sure I can think of an example in which a ‘state within a state’ is possible, so my suggestion would be to ‘flatten’ the states if possible.

Let’s consider a trivial scenario where we have a state-within-a-state modelled with two sealed classes:

sealed class A(open val b: B) {
data class A1(override val b: B) : A(b)
data class A2(override val b: B) : A(b)
}

sealed class B {
object B1: B()
object B2: B()
}

To flatten these states into something a single state-machine could represent, we’d have to use the product of the two classes:

sealed class AB {
object A1B1 : AB()
object A1B2 : AB()
object A2B1 : AB()
object A2B2 : AB()
}

Obviously, this works well for a minimal number of states but grows exponentially with the more you need to track. If you have a specific example you’d like me to examine, do let me know.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ed Holloway-George
Ed Holloway-George

Written by Ed Holloway-George

Lead Android Developer @ ASOS | Google Developer Expert for Android

No responses yet

Write a response