Search code examples
design-patternsnavigationstrong-typingdynamic-typing

Which is the correct design pattern for navigation?


I have an application which collects data from a user through a series of screens. On each screen there is a next button. On each screen there is a back button. However the screens aren't always sequential and linear. For example if payment has already been taken and the user is on the confirmation screen, when they click back they should be taken to an edit booking screen. I decided I need an object called a 'StateMarshaller' which would understand things about the domain, and would expose next(string action) back(string currentLocation) functions. Then it would return a 'State' object and tell the app where to go.

I just wondered if anyone can recommend a good pattern to aim for as we build up our test cases and refactor, I was looking at the command or the iterator but not totally feeling them. I think part of the problem is that I am used to strong typing but am now using a dynamic language.


Solution

  • It seems that you can benefit from using the State Pattern.

    enter image description here

    The idea will be that you will have a State for every screen. Each screen will do its own checking to determine where the user would go to next when hitting the appropriate buttons.