You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm interested in statecharts as a paradigm, and I'm considering using it for some projects.
I wanted to get grips with the mindset before I invested any real time into it. I've read and watched a fair amount now, and I hope it's starting to sink in.
However, I keep running up against hypothetical use cases where I don't know how/if statecharts should handle it. I thought I would list three of those and see what the pros suggest.
Scenario 1:
Imagine I have a device which can be in one of five modes.
Every 20ms I send the device a command, which is just a string of bytes. Based on the contents of the cmd, the device may remain in the same state (ie, its current mode), or may jump to any of the other four modes.
The command concerns itself with more than just switching the device's mode, so the function that parses it is doing other things than just this one state transition. (Eg it could be altering the device's config parameters, or telling sub-modules of the device to flash their LEDs.)
So I know the "event" here is "receive cmd". But that event could entail any state change or none, so how do I draw it on the state chart?
Scenario 2:
Imagine a checkout process on a website, where the user is expected to proceed through five stages (eg order summary, shipping information, billing information, payment, order confirmation).
Each stage naturally proceeds to the next, but there's a breadcrumb section at the top allowing the user to jump to any stage, from any stage.
Obviously, linking each state to each other state results in combinatorial explosion and is ridiculous. I imagine that the way to implement this is to have the five stages as separate states living within a parent, and have the breadcrumb transitions defined as five separate transitions on the parent, one to each state.
But does this mean that I need to manually code a separate transition and callback for each breadcrumb? That doesn't feel very efficient; what if there were fifty breadcrumbs instead of five?
(Yes, okay, a flow with fifty breadcrumbs is contrived. My generalised question here is: what is statecharts' answer to repetition - ie, how do you solve situations that in normal code you'd do with arrays, for loops, or while loops?)
Scenario 3:
I have a form full of widgets.
One of the widgets is something like a date selector field, the ones where a little calender pops up on focus. Ie, a small amount of state, easily modelled as a state machine on its own.
From the "outside perspective" now, I'm creating the state machine to control the form itself.
There are several dates to enter, so I want to re-use the widget multiple times on the form. How do I include my widget?
So, copy/pasting the same constellation of states in there multiple times is of course dumb, we want code reuse.
I've seen people talking about the Actor Model, as a sort of extension to statecharts. I haven't got to grips with thinking in actor-systems yet. I definitely need to though.
But even if I had, I don't know if this simple widget qualifies as an "actor". If there were only one widget on the form I certainly wouldn't bother to think of it as something separate.
So wat do in this situation?
Those are three off the cuff situations where I wouldn't know how to approach with statecharts. There are probably more, but I think hearing the right way to solve these would be a great start. Does anyone have any comments?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello.
I'm interested in statecharts as a paradigm, and I'm considering using it for some projects.
I wanted to get grips with the mindset before I invested any real time into it. I've read and watched a fair amount now, and I hope it's starting to sink in.
However, I keep running up against hypothetical use cases where I don't know how/if statecharts should handle it. I thought I would list three of those and see what the pros suggest.
Scenario 1:
So I know the "event" here is "receive cmd". But that event could entail any state change or none, so how do I draw it on the state chart?
Scenario 2:
Obviously, linking each state to each other state results in combinatorial explosion and is ridiculous. I imagine that the way to implement this is to have the five stages as separate states living within a parent, and have the breadcrumb transitions defined as five separate transitions on the parent, one to each state.
But does this mean that I need to manually code a separate transition and callback for each breadcrumb? That doesn't feel very efficient; what if there were fifty breadcrumbs instead of five?
(Yes, okay, a flow with fifty breadcrumbs is contrived. My generalised question here is: what is statecharts' answer to repetition - ie, how do you solve situations that in normal code you'd do with arrays, for loops, or while loops?)
Scenario 3:
So, copy/pasting the same constellation of states in there multiple times is of course dumb, we want code reuse.
I've seen people talking about the Actor Model, as a sort of extension to statecharts. I haven't got to grips with thinking in actor-systems yet. I definitely need to though.
But even if I had, I don't know if this simple widget qualifies as an "actor". If there were only one widget on the form I certainly wouldn't bother to think of it as something separate.
So wat do in this situation?
Those are three off the cuff situations where I wouldn't know how to approach with statecharts. There are probably more, but I think hearing the right way to solve these would be a great start. Does anyone have any comments?
Beta Was this translation helpful? Give feedback.
All reactions