basically serialize/deserialize just the class kin...
# getting-started
y
basically serialize/deserialize just the class kind, I don’t care about the state of the class itself
m
maybe I'm not understanding the question, but why not provide the actual class as the argument for the function that changes the state?
Copy code
when(yourClassInstance){
    is State1 -> doState1Thing()
    is State2 -> doState2Thing()
}
or otherwise, you can just get the class with
Copy code
yourClassInstance::class
y
because I want to make the class type the alphabet of the state machine, and I want to make different state machines over this alphabet
and I want an easy way to encode the states for each such FSM
is
someClass::class
going to be the same for each run, and independent of the state of the that class’s instance?
s
yes, the class of an instance is independent of the state of that instance.
m
Yes, it's metadata about the class itself and not the actual values within those classes.
y
thank you
m
You can also retrieve all your possible states if you ask the following from your sealed parent if you need to
Copy code
SealedParent::class.sealedSubclasses
👍 1
y
oh, very nice.
so my alphabet’s type is going to be a
KClass
.
m
well if you need to store it somewhere, it can even be a string
Copy code
yourClassInstance::class.simpleName
it all depends on your usecase
y
might be easier to just make 2 simple
when
clauses to translate to/from some compact representation like a byte.
the translation back is a problem, kinda.
but I don’t think I need it.
basically this looks like a giant XY problem the more I think about it
m
well if you need to (de)serialize the actual values then yeah
otherwise, if your statemachine is just that: Different states, I'd argue you should keep them as enums or sealed objects instead and let them be a value of a class