I was using State Pattern in a normal state machine. I wanted to be able to go from [A -> B], [B -> C], and [A -> C]. Now our domain has a new rule, now i need to go from [C -> A] also,but only if i have never been in B before. So we have states with memory. There are two possible solutions:
- Create a new State CB wich means C after B, and have these rules [A -> B], [B -> CB], [A -> C], [C -> A]
- Use the fact that our Context has a list with the previous states (lets call it StateHistoric) and the date when the transitions were made (the state history is also a domain requirement of our customer), and then use these rules [A -> B], [B -> C], [A -> C], [C -> A if B IS NOT in Context.StateHistoric].
Which of the two is a more correct way of using memory for the State Pattern? (or another alternative to these 2)
Thanks