hekailiang / squirrel

squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
http://hekailiang.github.io/squirrel/
Other
2.19k stars 540 forks source link

New history type 'recursive' #148

Open InigTril opened 4 months ago

InigTril commented 4 months ago

Hi,

Thanks for your work on this library which has a lot of features!

I created this issue to discuss two aspects of the history feature. I have attached a state machine diagram to illustrate my thoughts.

First, the history feature is implemented as a property of composite states instead of a pseudo-state as specified in OMG UML. I am not against that, but the documentation should be clear.

Secondly, I propose a non-UML feature on the history; a new type 'HistoryType.RECURSIVE', noted H+. The existing Shallow and Deep histories let a a composite state resume in its direct last active child or in its deepest last active child, but nothing in between. Moreover, let's say you have a composite state L1_B itself composed of two composite states L2_B and L2_C. L1_B should enter its direct last active child, and if it is L2_B, its own last active child should be activated, but if it is L2_C, it should start back to its initial state. Neither Shallow nor Deep history allow this configuration. That's why I propose the Recursive type which will enter the last active state of each nested composite state as long as they themselves have the Recursive history property.

I am working on an implementation for my own project. My project is private, sorry, but I am willing to share the recursive history feature in a pull request if you are okay with this.

FSM_RecursiveHistory