1

I'm looking for suggestions regarding implementing process flow / work flow management in a PureMVC based application.

Our Flex application includes a number of processes such as account creation, payment processing, etc.

Within our team, there is some discussion of how rigidly we should adhere to the PureMVC model.

Within the PureMVC model, it seems reasonable that the current state in the process could be managed in a Proxy.

Commands are clearly responsible for processing the actions required of each node and for node transitions.

Mediators for managing the UI.

However, I think that there is an important bit still missing here: a ProcessController.

The approaches we've reviewed all seem to either violate the PureMVC model (even just slightly) or make unreadable code.

  • A proxy would maintain the state of the process. As such, it seems to be an appropriate way to implement the controller. However, this is putting a lot of business logic into the proxy.

  • The Mediator space makes more sense, but the controller in that space would not necessarily directly interact with any particular UI element but would instead coordinate/delegate to dedicated Mediators.

  • Yet another model would have us put process transition information into Commands. While this seems to be the best place for that work (given the role of commands relative to proxies and mediators), this approach looks to make some particularly heinous looking code with process transition logic distributed among scores of commands.

So how have others handled this problem?

Thank Curtis

  • Simple, don't use PureMVC because it's horrible :P – J_A_X Oct 12 '11 at 05:16
  • I totally agree about PureMVC! I'll move the whole damned thing to internet standard techs (HTML5, REST) before I'll bother yanking PureMVC. – Curtis Patrick Oct 12 '11 at 16:51
  • At least you have options for MVC libraries in Flex. If you were to move to HTML5/Javascript, you'll be in a much greater world of hurt unless you use something like Google Web Toolkit. – J_A_X Oct 13 '11 at 01:14

3 Answers3

4

This is exactly the problem that PureMVC StateMachine Utility (and Finite State Machines in general) are meant to solve.

In a simple XML format, you can define states, valid transitions to other states, and the actions that trigger those transitions.

It is all notification-based, so you send StateMachine.ACTION notifications that cause the StateMachine to execute any entering/exiting guard logic that may be necessary (e.g., only allow exiting the FORM_ENTRY state if all the data valid, or only allow entry into the FORM_PROCESSING state if the user has admin rights, etc.). If a state change occurs, notifications are sent that can be used to organize the view or execute logic upon entering the new state.

Here is a StateMachine Overview presentation that will give you a better idea http://puremvc.tv/#P003/

Cliff Hall
  • 51
  • 4
1

I think your idea of 'ProcessController' is probably the better way of doing it. Personally, I'm not a fan of PureMVC and don't use it because it doesn't allow enough flexibility or extension points to help with such problems.

Frankly, it's hard to advise on your issue because I don't know exactly what you're trying to accomplish. I do agree that the concern needs to be handled by one object. If you can, try to create a model that can store the data for the process and have another class just manage it throughout. Not sure if that makes sense, but then again, your problem isn't very clear either.

As an added extra, I would look into Dependency Injection. I'm trying to remember if PureMVC does it (I don't think it does), but with DI it would of been a fairly simple problem to solve. Frameworks like Parsley and Robotlegs are really good at that.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • Sorry if the description is poor. In essence, I'm looking to implement something functionally equivalent to Spring WebFlow or even Struts, but in a Flex based application. No DI in PureMVC :( – Curtis Patrick Oct 12 '11 at 16:53
  • Spring/Struts in Flex is called Parsley or Robotlegs ;) – J_A_X Oct 13 '11 at 01:13
  • I use RobotLegs a lot and you run into the same exact problem you're having. Besides DI and automatic handling of mediators, RobotLegs and PureMVC are very similar. Oh, and RobotLegs uses stock flash events dispatched from a context-specific "event dispatcher" instead of PureMVC's notification class. The implementation is different, but the idea is the same. I use RobotLegs because it's a lot simpler, less boiler plate, handles most of my registration for me, and has DI. FWIW, I think Cliff's (author of PureMVC) solution below is what you need. I wonder if a utility like that exists for RL!? – Jonathan Rowny Dec 13 '11 at 18:10
  • OH! it does exist: https://github.com/joelhooks/robotlegs-utilities-StateMachine very cool. – Jonathan Rowny Dec 13 '11 at 18:11
  • Thanks for pointing out RobotLegs. Replacing PureMVC isn't an option (and not something I'm entertaining anyway), but I really like the idea of DI in AS3. Thanks! – Curtis Patrick Jan 31 '12 at 00:05
0

In pureMVC the State Machine Utility is probably the best choice for a process controller - and btw, according to the Implementation Idioms & best Practices doc. for PureMVC, it's perfectly fine to have mediators that don't manage a visible component