Implementing process workflow in PureMVC

379 views Asked by At

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

3

There are 3 answers

0
rajeshpatel On

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

1
Cliff Hall On

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/

5
J_A_X On

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.