`
maplye
  • 浏览: 114660 次
  • 来自: ...
社区版块
存档分类
最新评论

Which Style of Workflow When?[转]

    博客分类:
  • .NET
阅读更多
http://blogs.msdn.com/davegreen/archive/2005/10/20/483309.aspx

Windows Workflow Foundation supports three basic styles of workflow:  Sequential, State Machine and Data-Driven. 

I get a lot of people asking me which style is right for their problem, so I thought I’d share my thoughts on this with you all.

Let’s start with a simple problem.  I want Fred to review a document, then Joe to approve it, and finally I want to send it to my customer.

This is an obvious Sequential style workflow.  To implement it, I create a Sequential Workflow project, add a sequence of Activities which ask Fred to review, Joe to approve, and finally myself to send the document – and I’m done.

A Sequential workflow is characterized by the fact that the workflow is in control.  Fred, Joe and I get to do what we’re told, when we’re told to do it.  We do our stuff, let workflow central know that we did it, and then the workflow decides what happens next.

Of course, the Sequential style doesn’t mean that things always happen in a simple linear sequence like this.  We can have conditional branching, loops, and so on.  What it means is that the workflow controls the sequence.  The Sequential style is the classic style of workflow, as implemented by dozens of products over the years. 

In my opinion, it is also significantly responsible for giving Workflow a bad name.  Not that there’s anything wrong with telling people what to do (I’m known to indulge in the practice myself, occasionally) – but sometimes it just doesn’t work.

Let’s look at an example.  Say that I’m testing a product that’s being developed.  When I find a problem, I open a bug, assign it to the guilty developer, then wait confidently for the fix. I want to write a workflow to manage this process.

So far, this sounds very familiar.  The steps are: tester opens bug, developer fixes bug, tester approves fix.  Just like the simple document review we saw before.

But this is illusory.  What really happens?  A tester opens a bug, and assign it to Bill.  Bill says, no not me, this is Clive’s, and reassigns the bug to him.  Or Bill says, this tester is not in this case quite correct (or words to that effect), and rejects the bug as nonsense.  Or asks the tester for clarifying information.  Or even, if he’s in a good mood, fixes it and hands it back to the tester.  Or, if the original tester is out, another tester.  Or the tester withdraws an erroneous bug (surely not).  And so on, with each participant being able to make one of a set of choices at any given stage.

What happens if I write this in the Sequential style?  Something like this (if you’ll forgive my pseudocode):

               Tester T creates instance of bug workflow
               T adds bug details
               T assigns to developer D
LabelA:     Switch
                     D assigns to developer E
                           Goto LabelA
                     D rejects bug to T:
                           Switch
                                 T accepts rejection:
                                 T updates bug and assigns to developer F:
                                          Goto LabelA
                           End Switch
                     D requests info from T:
                     T submits info
                           Goto LabelA
                     D submits solution to T:
                     T withdraws bug:
               End Switch

You get the idea.  Loops and choices which arise within choices are posing structural questions (here I held my nose and used Goto, to try and keep the mapping from the scenario to the code obvious).  And if we start making the process more realistic still, with a queue of bugs coming in that a development team leader assigns to individuals (or a developer might grab them from the queue), and we add a project manager to the picture with the ability to set bug priorities in flight, and so on, things will get worse and worse.

This problem is much better tackled using the State Machine style.  The pseudo-code above becomes:

State: Initial
      Action: T adds bug details
      Action: T assigns to developer D; new state = Fixing

State: Fixing
      Action: D assigns to developer E
      Action: D rejects bug to T; new state = Rejected
      Action: D requests info;  new state = Pending Info
      Action: D submits solution; new state = Pending Approval
      Action: T withdraws bug; new state = Closed

State: Rejected
      Action: T accepts rejection; new state = Closed
      Action: T updates bug and assigns to developer F; new state = Fixing

State: Pending Info
      Action: T submits info; new state = Fixing

State:  Pending Approval
      Action: T rejects solution; new state = Fixing
      Action: T accepts solution; new state = Closed

State: Closed

This is much cleaner and more comprehensible.  Also, adding more features will not complicate the structure – it will simply mean adding more states and actions.

Implementing this style in Windows Workflow Foundation is simply a matter of creating a State Machine Workflow project and defining the states and actions required.

So what’s the criterion for using the State Machine style?  Simply this: are the important choices being made outside the workflow?  Is the user in control?  If so, then the Sequential workflow’s notion that it calls all the shots will become a nuisance.  The State Machine style of workflow, on the other hand, expects the choice of what to do to be made outside the workflow.

So if the workflow makes no choices, what is it for?  Well, a State Machine workflow controls the sets of choices.  It makes no sense for a tester to accept a solution until one has been submitted.  It only becomes valid when the bug workflow has reached an appropriate state – by one of a large number of possible routes.

It’s this last point that leads us to another insight about why the State Machine style is more applicable to this problem.  The Sequential workflow, of its nature, encodes all the possible sequences of behavior in its structure.  But here, we don’t care.  We only need to know about the current state, and what can be done next.  So if we spend time modeling routes through the process, event though we don’t in fact care about them, and these routes are many, as they are in the bug problem, then the Return On Investment from the Sequential style inevitably becomes very poor.

OK, so far, so good.  What’s this third, Data-Driven, style about?

This time, we’ll use the example of an inventory shortfall.  An assembly line is making a gadget, and the computer said there were enough widgets in stock for the purpose, but when the stockroom manager went to fetch the widgets, there was a shortfall of 10.

We want to build a workflow to handle this scenario.

What are the possible actions?  The supplies department could order more widgets, perhaps going to a different supplier or paying more money for faster delivery.  The account manager could go to the customer and defer delivery, or split the delivery in two parts and bear the extra shipping cost.  The production manager could take assembled gadgets from an order for another customer and divert them.  The stockroom manager could search his stock to find the missing widgets.

Our workflow will be a collaboration, containing all these actions, restricted to the appropriate roles.  Any given action might be performed multiple times.  One obvious constraint is that the collaboration is not done until the shortfall is fixed by some combination of the above actions.

There will also be business constraints.  For instance, there may be a rule that says deferral of delivery to gold customers is never permitted.  Also, the actions will affect each other.  For instance, we may say that total added cost from corrective action may not exceed 5% of original factory cost – so placing an order for accelerated supplies might prevent a shipment being split.

This is not a Sequential workflow – all the decisions are being made outside the workflow.  Is it a State Machine workflow?  Clearly, the sets of actions allowed to each role varies as the collaboration progresses – as splitting shipments becomes impossible, for instance – and the workflow is determining these sets of actions.

But the set of actions available at any given point is determined by the interaction of a number of  independent rules – whether the customer is a gold customer, whether we have already deferred delivery once, whether the profit margin on the order is becoming a problem, etc.  So the number of possible sets of actions – and therefore the number of corresponding states – is going to be large. 

Crucially, we’re actually not interested in what these possible combinations of actions are – only that the rules are enforced.  So we find ourselves again in a situation where a modeling approach, in this case the state machine, captures information we don’t care about – and therefore has poor ROI.

What do we get ROI from modeling?  Why, simply what are the available actions, and who can perform them under what circumstances.  This is just a set of actions, and for each, a role and a boolean expression which determines availability.

There is one more thing.  We’d like to know when our collaboration is done – so we add to the model another boolean expression which is true when the collaboration is finished.  In this case, the expression will test whether there are, or will be, enough widgets in stock for assembly.

How is this Data-Driven style implemented in Windows Workflow Foundation?  There are two model elements to support this approach:  the Constrained Activity Group, and the Policy.  Both are typically used within a Sequential Workflow project, and represent regions of ‘data-drivenness’.

Clearly, it would be possible to model all workflows in this Data-Driven style.  Wouldn’t we then have only one modeling approach to worry about?

This is true, but not optimal.  To see why, consider how we know that a Data-Driven workflow is correct.  We cannot predict its behavior very easily at all – the number of possible different series of actions that the workflow will allow is very large.  So really the only way to test it is to try it, using enough different initial states, and enough different paths through it, that we feel confident in its operation.

Contrast the testing of a Sequential style of workflow.  It has only a few possible sequences of behavior, which we can test exhaustively.  We can get a higher level of confidence more cheaply.

So the motto is, choose the workflow model which has as much structure as your problem has – and no more.  Deviating in either direction costs you money.  Using a style with too much structure adds cost because you’re encoding information which has no value.  Using a style with too little structure adds cost because your testing costs are higher than they need to be.

And one final word.  Do not think that a typical real world application should use only one style.  Most applications are most cost-effectively built from a composition of styles.  Consider a Call Center application where most of the time the system uses scripts to drive the telephone operators.  Probably a  Sequential workflow.  But then there are always the exceptions, such as an account in a shouldn’t-have-got-there state.  Now we want to refer to an expert.  Experts need to make choices – and so should be supported with a State Machine or Data Driven workflow.

So there you have it – my thinking on styles of workflow in the Windows Workflow Foundation.  Feedback, as ever, solicited and welcome!

  

 

 

Published Thursday, October 20, 2005 8:37 PM by Dave Green
分享到:
评论

相关推荐

    An Overview of Workflow Management:From Process Modeling to Workflow Automation Infrastructure

    ### 工作流管理概述:从过程建模到工作流自动化基础设施 #### 一、引言与背景 在当今全球化的商业环境中,企业面临着日益激烈的竞争压力,为了保持竞争力,企业必须降低成本、快速开发新产品和服务。...

    工作流(WorkflowService)WebService接口使用说明.doc

    工作流(WorkflowService)是泛微协同办公系统中一个关键组件,它提供了通过WebService接口与外部业务系统进行数据交互的能力。本使用说明旨在详细介绍如何利用这些接口进行有效的流程管理和任务处理。 1. **检查...

    TMS Workflow Studio v1.9.0.0 Full Source

    Improved : Better performance for saving/loading workflow definitions, instances and tasks when using ADO Fixed : Workfklow blocks not displayed when language different than English was used Fixed : ...

    Beginning WF: Windows Workflow in .NET 4.0

    Beginning WF demonstrates, in an eminently readable and accessible style, how Microsoft's Workflow Foundation (WF) technology can be used in a wide variety of applications. Loaded with lots of simple ...

    Research on the Workflow System of Collaborative Process Planning

    Research on the Workflow System of Collaborative Process Planning

    uipath level 1 lesson 13参考答案.docx

    7. **What type of arguments can you use in a workflow?** 在工作流中,可以使用“In/Out”类型的参数,以传递输入和输出数据。 8. **What is considered a best practice in large projects?** 大项目中的最佳...

    simple workflow

    在描述中提到“very easy to understand the idea of workflow”,这表明这个压缩包可能包含了一些基础示例或教程,旨在通过直观的方式解释工作流的基本原理。通常,工作流系统会包括定义工作流程、分配任务、跟踪...

    Laravel开发-laravel-workflow

    **Laravel 开发 - Laravel Workflow** 在 Laravel 开发过程中,我们常常需要处理各种状态转换,例如订单的状态(待支付、已支付、已完成等)或文章的状态(草稿、审核中、发布)。`Laravel Workflow` 提供了一种...

    demo of workflow

    本示例“demo of workflow”将展示如何通过Java语言实现一个工作流系统。Java作为一种广泛使用的编程语言,拥有丰富的库和框架来支持工作流的开发。 首先,让我们了解一下工作流(WF)的基本概念。工作流是指一系列...

    Hue-workflow配置流程

    Hue的Workflow(工作流)组件则是用于构建和管理复杂的Hadoop作业流程,允许用户通过拖拽操作来设计数据处理任务,而无需编写复杂的命令行脚本或Java代码。在本文中,我们将深入探讨如何使用Hue配置和运行一个...

    lotus的workflow教程

    回想自己学习Domino Workflow的经历,也算有些坎坷,因为这方面的资料很少,Domino Workflow的帮助库虽然比较完整,但是缺乏一个主线,而且没有一些实用技巧的介绍。心中一直有一个想法,就是将自己掌握的Domino ...

    数据库WorkFlow表结构

    数据库WorkFlow表结构 数据库WorkFlow表结构是小型工作流系统的一种解决方案,该表结构主要由五个表组成:flow_form_type、flow_type、flow_process、flow_run和flow_run_prcs。每个表都有其特定的字段和关系,用于...

    workflow_springbootworkflow_workflowdemo_workflowspringBoot_work

    工作流(Workflow)是软件系统中用于管理业务流程自动化的重要技术,它可以帮助组织或企业实现流程规范化、提高工作效率。在本项目"workflow_springbootworkflow_workflowdemo_workflowspringBoot_work"中,开发者...

    Oracle Workflow Builder

    ### Oracle Workflow Builder 知识点解析 #### 一、Oracle Workflow Builder 概述 Oracle Workflow Builder 是一款由 Oracle 公司开发的企业级工作流管理工具,它被集成在 Oracle 应用服务器中,并且作为 Oracle ...

    Laravel开发-workflow

    'Workflow' => \Symfony\Component\Workflow\Workflow::class, ``` 现在我们已经准备好了基础架构,可以开始定义工作流了。在 Laravel 中,可以创建一个新的 PHP 类来表示工作流定义。例如,创建一个 `src/...

    workflow实现的源代码

    【标题】"workflow实现的源代码"涉及到的是工作流(Workflow)系统在信息技术中的实际应用,尤其是OA(Office Automation)系统的开发。工作流系统是一种自动化业务流程的技术,它能够管理和控制文档、信息或任务在...

    简单的workflow方便用户快速用VisualStudioCode打开自己的项目

    标题中的“简单的workflow方便用户快速用VisualStudioCode打开自己的项目”指的是通过自动化工作流程(workflow)简化了在Visual Studio Code(VS Code)中打开项目的过程。这个工作流程可能是一个脚本或者工具,...

    C# Workflow WCF EXAMPLE

    本文将深入探讨“C# Workflow”和“WCF”这两个关键概念,并结合提供的“WinForms”示例,阐述如何在实际项目中应用它们。 C# Workflow(工作流)是.NET Framework的一部分,它提供了一种模型化业务流程的方式。...

Global site tag (gtag.js) - Google Analytics