views:

110

answers:

5

I have a complex application with many pages.

Each page can have many possible routes to other pages: 'A' can go to 'B' or 'C', 'B' can go to 'A' but not 'C'. etc.

Rather than embed this "where to go to next" logic in each page (horror!) I of course want to encapsulate it in a main point of control. 'A' doesn't need to know about 'B' or 'C'.

Even better, I'd like to reduce the problem to a matter of configuration.

This isn't a language/framework specific question -- it's a matter of how best (simple, pragmatic) to represent and interpret Workflow logic.

Has anyone had experience representing a complex flow between points in an application as a configurable setting?

A: 

You might be able to use something like the .NET work flow foundation to represent this neatly.

oykuo
A: 

This is basically a state machine, where each page represents a state and the transitions are stored in your configuration. Google for that, you'll get samples which may help.

Lucero
+4  A: 

What you describe is a pretty classic Finite State Machine. You have States (Pages), Navigation (Transitions), but also you can have things like entry/exit actions and transition conditions.

With that said, it's worth thinking about your navigation, do you simply want a list of navigation options dynamically added to the page, or is there some extra smarts involved. Think of when the navigation is valid, what information is required for the navigation, the data you might want to bring with you to the next navigation etc.

I've created state maps before by simply using XML, eg:

<states>
  <state name="Open">
    <transition action="Close" state="Closed" />
  </state>
  <state name="Closed">
    <transition action="Open" state="Open" />
    <transition action="Lock" state="Locked" />
  </state>
  <state name="Locked">
    <transition action="Unlock" state="Closed" />
  </state>
</states>
Timothy Walters
A: 

Pretty much every Web Application framework has to tackle this problem. For java, take a look at Struts2, Spring MVC, Tapestry, Wicket, etc. to see the various approaches. (XML is naturally a common method of capturing the transition information in an external config file.)

A: 

Press On covers this sort of thing in some depth. (Using explicit representations of state machines and statecharts in design and implementation of user interfaces.)

Darius Bacon