KStateMachine / kstatemachine

KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
340 stars 19 forks source link

DSL is mutating the states #23

Closed sabomichal closed 2 years ago

sabomichal commented 2 years ago

This machine has one fundamental problem, that you can not instantiate more than one instance of the State Machine, since it is not building its own immutable State graph based on the State definition, but the DSL is mutating the inner state of the State itself.

nsk90 commented 2 years ago

Hi! I wrote about it in "Do not" readme section. https://github.com/nsk90/kstatemachine#do-not

Mutable state graph will help if you use only default states (without data attached to them), but if you use DataState or your own State subclass the problem will be still actual.

I think it is easier to avoid using singleton states if you have more than one instance of same state machine, than add mutable state graph abstraction.

Does removing object from your state definitions help you or I missing something?

sabomichal commented 2 years ago

Ah, ok, I was unaware of that section.

Sure, you can always do it one way or the other and my issue description is a bit wrong - the mutable state definition is a limitation only when you define the states in advance, avoiding so the lateinit or stub states definitions at the beginning of the State machine definition.

nsk90 commented 2 years ago

Yes, using object States may simplify state machine creation function.

The idea of mutable state graph is ok, so maybe it should be tried.

Attention also should be payed to:

nsk90 commented 2 years ago

I took a look at the idea of moving State mutability to another object (state graph). Here are some points on that:

So I do not think it should be implemented. If you have some thoughts on this, please share :)