In article <200404071430.54512 / vadim.nasardinov>,
Vadim Nasardinov  <vadimn / redhat.com> wrote:
>On Wednesday 07 April 2004 14:19, Hal Fulton wrote:
>> That's pretty interesting. I've never yet conceived of a state-
>> machine approach in that kind of situation.
>
>I liked this book a lot:
>  "Constructing the User Interface with Statecharts"
>  by Ian Horrocks
>  ISBN: 0201342782 
>
>(But then again, since I don't write GUIs, I haven't had a chance
>to try out Horrocks' ideas in practice.)

Looks like an interesting book.

As I mentioned earlier, as a former hardware engineer (you use state 
machines everywhere in hardware design) it just seems natural to use a 
state-machine as the underlying logic for a GUI. You've got events coming 
in (button presses, generally) and you transistion to different states in 
the machine depending upon the interaction and data provided by the user. 
It's easy to keep the underlying logic seperate from the actual GUI 
code when you use a state-machine.

So in the UI I'm currently developing (I say UI because it can be 
console-based or GUI based depending on the environment it's running in) I 
have a login-state for logging into a site (asks for user-name and serial 
number).  If the user is using the GUI they type in the info into a 
couple of text boxes and then hit the 'next' button and the http 
connection is attempted, if successful the machine moves into the next 
state and the GUI is notified to display the next tab.  In this case the 
next botton generates the event to the 
state-machine.  If the user is using the console version of the same app, 
in the login-state they're asked to enter their email address and then to 
enter their serial number. The second 'return' after entering the 
serial number triggers the event to the state-machine and the connection 
is attempted, and again, if the connection was successful the machine 
moves into the next state where another set of questions is asked on the 
console.  The same state-machine can be used in both cases since the 
state-machine itself has no GUI/UI code in it.

I kind of thought everyone did things this way, but it sounds like it 
isn't common practice.

Do others use state-machines for this sort of thing?


Phil