Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

State Machines and User Interface work -- any examples/experience?

I'm looking for ways to de-spaghttify my front-end widget code. It's been suggested that a Finite State Machine is the right way to think about what I'm doing. I know a State Machine paradigm can be applied to almost any problem. I'm wondering if there are some experienced UI programmers who actually make a habit of this.

So, the question is -- do any of you UI programmers think in terms of State Machines in your work? If so, how?

thanks, -Morgan

like image 331
morgancodes Avatar asked Feb 27 '09 15:02

morgancodes


People also ask

What is an example of a state machine?

There are many more examples of finite state machines we could use: a vending machine. a subway entrance turnstile. a heating system.

How does a state machine work?

A state machine has some internal state that can be changed in response to an external event. When a state machine receives an event from the external environment, it changes its state to a new state in accordance with a simple rule. It may also perform an action with significance to the external environment.

Why do we use state machines?

A state machine is often a very compact way to represent a set of complex rules and conditions, and to process various inputs. You'll see state machines in embedded devices that have limited memory. Implemented well, a state machine is self-documenting because each logical state represents a physical condition.

What is a state machine in gaming?

A finite-state machine is a model used to represent and control execution flow. It is perfect for implementing AI in games, producing great results without a complex code. This tutorial describes the theory, implementation and use of simple and stack-based finite-state machines.


1 Answers

I'm currently working with a (proprietary) framework that lends itself well to the UI-as-state-machine paradigm, and it can definitely reduce (but not eliminate) the problems with complex and unforeseen interactions between UI elements.

The main benefit is that it allows you to think at a higher level of abstraction, at a higher granularity. Instead of thinking "If button A is pressed then combobox B is locked, textfield C is cleared and and Button D is unlocked", you think "Pressing button A puts the app into the CHECKED state" - and entering that state means that certain things happen.

I don't think it's useful (or even possible) to model the entire UI as a single state machine, though. Instead, there's usually a number of smaller state machines that each handles one part of the UI (consisting of several controls that interact and belong together conceptually), and one (maybe more than one) "global" state machine that handles more fundamental issues.

like image 152
Michael Borgwardt Avatar answered Oct 03 '22 20:10

Michael Borgwardt