2015. január 20., kedd

Implementing workflows

LinkedIn: What are the best choices for implementing UI page flows and Batch work flows

When I face this task, I consider the following (always appearing) tasks:
 - You MUST do the same when the process is done on a GUI or in a batch processing of thousands of cases - so you MUST use the same codebase. Period.
 - The flow (the states, paths, control conditions and addressed objects) WILL change in time. The more business logic you write in code (and almost alike: annotations, magic XMLs of various toolkits) the sooner you will get hurt. Not to mention that sometimes you are asked to open the flow for editing to customer administrators.
 - The users will NOT read the manuals, so they will get angry unless they get all information: what are the available options, what they mean and why other options are not available.
 - Unfortunately, sometimes external toolkits also change, so if they appear in your codebase, you have to follow them (and in worst case, your users will also have to adapt to the change).

Now to the better news:
 - A workflow is a mesh network of State and Transition "objects". It is really easy to store this network, even in simple JSON if you like (each state has unique ID which is referred in the Transitions). That means you can send it to a JavaScript client and display to the user as well.
 - In general, the transitions have conditions, which are expressions. If you can give a homogeneous access to the objects around the transition, this can also be configurative, because there are many expression parser/evaluator solutions.
 - You should consider creating a homogeneous status reporting environment. Then, you can "ask" each related object (Person, Employee, Office, Shelf, Truck, whatever) about their current state; the Transition expression can access their data and state content and decide if the transition is allowed, and also report to the status container (what the user should do to enable this transition).
 - So, you can show the workflow to the user (because it is not hidden in magical configurations and source codes). You can inform them about the current state anytime without extra coding. And if there is no user, the batch processing can also use the same information: you replace the "user" with scripts, similar to the transition expression, but this time the result is the next state.
 - Still, you can use any "well known solution" for actually managing the workflow, so you get the solid, tested implementation; your extra effort is to convert your configuration to its native format. However, you are independent from the chosen tool; you can upgrade or replace it at a later time because you can forecast the efforts and side effects.

... my 2 cents...