We are faced implementing a registration workflow with many branches. There are three main flows which in some conditions lead to one another. Each flow has at least four different steps; some steps interact with the server, and every step adds more information to the state. Also the requirement is to have it persistent between sessions, so if the user closes the app (this is a mobile app), it will restore the process from the last completed step with the state from the previous session.

I think this could benefit from the use of the strategy pattern, but I've never had to implement it for such a complex case. Does anyone know of any examples in open source or articles from which I could find inspiration? Preferably the examples would be from a live/working/stable application.

I'm interested in Java implementation mostly; we are developing for Java mobile phones: android, blackberry and J2ME. We have an SDK which is quite well separated from platform specific implementations, but examples in C++, C#, Objective-C or Python would be acceptable.

closed as off-topic by Ixrec, GlenH7, user40980, durron597, user22815 May 23 '15 at 4:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Ixrec, GlenH7, Community, durron597, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Hi Eugen and welcome to Programmers! You will have to tell us a bit more about the workflow, non trivial implementations are rarely based around a single pattern. Also, although we are focused on language agnostic questions, since you are asking for examples it would be helpful to tell us what languages you are familiar with. But keep in mind that most people here will be more interested in the conceptual side of your question. – yannis Jan 24 '12 at 7:12
  • 1
    Hi Yannis, thank you for correction. I've added languages but as you said it's quite general question that should be clear for any oo language. – Eugen Martynov Jan 24 '12 at 7:26
  • Sounds like a "chain of responsibility pattern" coupled to a factory for strategies for concrete steps. – Falcon Mar 24 '12 at 18:41

You should have a look at JHotDraw. It's sole purpose is to demonstrate patterns usage in real life.

jhotdraw.org is where it's at:

a Java GUI framework for technical and structured Graphics. It has been developed as a "design exercise" but is already quite powerful. Its design relies heavily on some well-known design patterns. JHotDraw's original authors have been Erich Gamma and Thomas Eggenschwiler...

JavaWorld published an introductionary article "Become a programming Picasso with JHotDraw". The accompanying example application JModeller - a simple UML editor built using JHotDraw - shows some of the described design patterns and demonstrates how to use and extend existing classes...

Besides the documentation which is included in the download package more information about the internal architecture of JHotDraw and guidance for using the JHotDraw can be found here:

  • A description of the design patterns used in JHotDraw in the form of a pattern language by Douglas Kirk. Especially, the pattern index in form of a clickable pattern map shows the relation of different patterns.
  • A case study about an older version of JHotDraw can be found in the dissertation of Dirk Riehle...
  • The link you refer to is written in German, would you mind explaining more on what it does and why do you recommend it as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange – gnat May 31 '13 at 13:14
  • 2
    1) The question is "can you point me" and a link does exactly that. – EricSchaefer May 31 '13 at 15:33
  • 2
    2) jhotdraw.org is where it's at – EricSchaefer May 31 '13 at 15:33
  • 2
    3) "It's sole purpose is to demonstrate patterns usage in real life." That's why I recommended it. – EricSchaefer May 31 '13 at 15:34

As Kevin Junhans already pointed out, this problem is really a question about implementing a workflow.

The strategy pattern isn't really applicable, it's purpose is more to make code generic by swapping out small portions of logic contained in "Strategies", not in orchestrating a larger process.

For Java there are a lot of workflow related options, of which I know two free and open source ones:

  1. jBpm
  2. Activiti

A good workflow engine will help persist long running processes (like when a user exits their session) and orchestrate actions between multiple systems (wait for user input here, call web service here, etc). Done right, your processes will also be easier to adjust in the future and verify with the business.

  • Hi Chris! Thank you for reply. Going to process resources soon. – Eugen Martynov Mar 12 '12 at 15:01
  • would you mind explaining more on what these resources do and why do you recommend these as answering the question asked? "Link-only answers" are not quite welcome at Stack Exchange – gnat May 31 '13 at 13:16
  • @gnat, How is this a link only answer? First, he needs a workflow engine, not a stratgey pattern. The links are to Java workflow engines, as noted in the answer. – Chris Pitman May 31 '13 at 18:00

Here is an example that does exactly what you are looking for. The example handles a web registration process that is persisted so the user can resume where they left off. It is implemented using ASP.NET MVC in C# with Windows Workflow Foundation.

  • Thank you Kevin. Our flows are a has more branches but article is helpful. – Eugen Martynov Jan 25 '12 at 18:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.