I have been doing some Windows Workflow (WF) consulting with a customer lately and I was talking to a developer who had just been thrown onto the project and was struggling with WF, not feeling that he had a solid grasp of the paradigm. No one was more surprised than me when I was able to help him so easily by simply pointing out that WF is an instance of the “Command Processor Pattern”. Because it seemed to help him so much I thought it might be worth sharing here.
Before I get to this however, I just want to state for the record how important I believe the Gang of Four (GoF) Design Patterns book is. I always assume, sometimes incorrectly, that every developer has intimate knowledge of the GoF Design Patterns book. I believe reading it is a right-of-passage for every developer, and I would always steer people towards the original book, as opposed to “knock-offs” that try to “translate it” to another programming language. If you haven’t read it, stop everything and read it!
The Command Pattern
In case you can’t recall it, the authors state the following as the intent of the “Command Pattern”:
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations
However, I think the essence of it is well captured in the structure diagram:

The Command Processor Pattern
After the GoF authors, the POSA1 authors expanded on the Command Pattern by writing up what they called the Command Processor Pattern, a pattern that built on the Command Pattern to show how easy it is to use it to do things like undo/redo functionality etc. Again, for the sake of brevity, I will only show a single UML class diagram that I think conveys the essence of the pattern:

Compounding Command
Later, two of the GoF authors wrote a paper called “Compounding Command” in which they showed how some of the other GoF patterns can be combined with Command in interesting and powerful ways, which I’ll summarize here by once again showing a single UML diagram that I think captures it quite well:

Finally, WF as an Instance of the Command Processor Pattern
Now, mapping these ideas to WF is, I think, as easy as first of all making the following connection:
Activity à Command
WorkflowRuntime à CommandProcessor
Armed with these mappings, then showing the structural relationship of some of the key classes in WF shows very clearly how it can be conceptualized as the “Command Processor Pattern”:

The Value of Patterns
As a final comment: the GoF authors state explicitly that they weren’t doing anything new but rather placing well thought out names to reusable design nuggets that people had been using for years already. The real value in that was evident in the interaction I had this week with that developer: once he thought of WF in the context of the Command Pattern he immediately understood what I was talking about because the pattern name was part of our "shared developer lexicon".
I am in the process of writing a new course for ObjectSharp on Windows Workflow Foundation (WF). More details about the course can be found here: http://www.objectsharp.com/training/coursedetail.aspx?id=1145. For even more information, contact our Training Manager, Julie James, at 416-216-4603 (or 1-877-So-Sharp) ext. 1 or via email at Training@objectsharp.com.
Taken along with the existing WCF course http://www.objectsharp.com/training/CourseDetail.aspx?id=1135, students will be given a hands-on guide to building a successful Service-Oriented Architecture (SOA) using the .NET 3.5 platform.
This saturday (March 1st) I will be giving a talk entitled "SOA Using WCF & WF" at the Toronto Code camp 2008. The site is here http://torontocodecamp.net/. My talk is in the .NET Framework track and the schedule for this track can be found at: http://torontocodecamp.net/Sessions/NETFramework/tabid/64/Default.aspx. The abstract for the talk is:
"In the world of SOA it is useful to classify your services into two types: Business Activity Services and Resource (or sometimes Entity) Services. In this demo-centric session we’ll look at how Windows Communication Foundation (WCF) and Windows Workflow (WF) can be used within this classification system. More specifically we’ll look at how WF is an ideal choice to use “inside the boundary” of your Activity Services to carry out the long-running work the service represents."
It looks like there are lots of good sessions so I hope to see you there.
Both the slide deck and sample code I covered at my presentation at Okdevberfest Code Camp
Last Saturday I gave a presentation at the "Okdevberfest" Code camp (http://www.okdevberfest.com/) held at the University of Waterloo. The slides as well as the sample code I covered can be found in the attachment above.
Cheers to Dave Totzke and his fellow organizers for putting together an excellent code camp.
A few people asked for the demos from this presentation.
Links for the presentation are at the bottom of the post
If you have not already set up your development environment for Windows Workflow Foundation (WF) Development, follow the below steps:
Prerequisites:
a) Windows XP, Windows 2003, Windows Vista
b) Visual Studio 2005
Install the following:
1) .Net Framework 3.0 Redistributable
2) Visual Studio 2005 extensions for .NET Framework 3.0 (Windows Workflow Foundation)
3) You can also optionally download and install:
Microsoft® Windows® Software Development Kit for Windows Vista™ and .NET Framework 3.0 Runtime Components
Before installing the above read the provided instructions.
Below are some resources for using/learning/developing with WF:
MSDN - Windows Workflow Foundation
MSDN - Windows Workflow Foundation Tutorials
MSDN - Windows Workflow Foundation General Reference
Getting Started with Windows Workflow Foundation Server Virtual Lab
Hands-on Labs for Windows® Workflow Foundation
Clinic 5136: Introduction to Developing with Windows® Workflow Foundation and Visual Studio® 2005
Windows Workflow Foundation Developer Centre
Also please read Paul Andrews blog (Windows Workflow Foundation Technical Product Manager at Microsoft) for the latest and greatest on WF.
Download the presentation demos here.
Please read this before trying to run.
Tomorrow (March 20) I am doing a presentation at the Metro Toronto .Net User Group entitled:
Fundamentals of Windows Workflow Foundation (WF).
Most of it will be demos introducing WF. Of course, I will also include BizTalk in the presentation, discussing the differences and similarities between WF and BizTalk and when it is appropriate to use either technology.
The demos will include:
Creating a Sequential Workflow
Communicating with the Host
Logging Workflows
Persisting Workflows
Creating Custom Activities
Creating a State Machine Workflow
Using WF and BizTalk together
You can sign up for the presentation here:
http://www.metrotorontoug.com/User+Group+Events/379.aspx