1

I have an action that does 2 things, first it will change the application state and second it makes a call out to a webservice. When the webservice sends it's response, it will affect the current application state.Example statechart

Lets say I have the above setup. Method1() calls the webservice and causes the state to change from A to B. After the Method1() call up to the Finish() call, the status can change from B to C, B to Success, etc..

If B changes to Success, it could also then change from Success to C.

How would I tie in the Success and Fail states when the state can be set at any point after the Method1() action?

Matt R
  • 2,577
  • 5
  • 30
  • 46

2 Answers2

1

I am not sure to really understood your whole issue but for designing your problem I would use events. A transition can be trigger when an event occurs so I would create an "ReceiveResponse" event and a transition between state B and the decision Node (as depicted below). This models the fact that if you state machine is in state B and receive a response the transition is triggered and will, according to the value of the response, change is status from B to Success or Fail.

Modelio state machine

Maybe could you describe a little more the possible transition or state possible? Is it possible for your object to be in two state at the same time?

Hoping it helps,

EBR

Red Beard
  • 3,436
  • 1
  • 14
  • 17
  • The application can be in a `B` or `State2` state when the `ReceiveReponse` event happens. If it happens when the app is in the `B` state, it's possible that the state then changes to `State2` – Matt R Nov 07 '13 at 15:55
  • First of all sorry for my mistake, I uploaded my previous response in order to keep state C instead of State2 ... – Red Beard Nov 07 '13 at 16:24
  • Now the aims of state machine is to list all the possible states and transitions of your object. It seems that you only have 5 possibles states, right? Could you details the possible transitions between them and explain when these transitions will be triggered. For example my object is in state B, the receive response occurs, if the response == false next state will be Fail if the response == true next state will be Success. If the current state is B and the Method2 is call next state will be C. E.g. I would know what happen is your object receive the response and the current State is not B? – Red Beard Nov 07 '13 at 16:31
  • Here is a scenario: Current state is `B`, the routine that checks for a response gets `response == true`, status is now `Success`, user calls `method2`, status is now `C`. Here's a different scenario which could also occur: Current status is `B`, check if we have a response (we don't), user calls `Method2()` and status changes to `C`, we finally receive a response and `response == true` status is now `Success` – Matt R Nov 07 '13 at 19:27
  • I uploaded the image in order to take into account your last comment. But I have some comments. 1)Are you sure that a state diagram is really the best way to depict your issue? 2)Maybe you have more to despict ... I mean maybe have you a "Waiting response" state which (with Success and fail) would be parallel to A and B states? 3) From my point of their is some error with your first diagram e.g. the transition between the initial state and A state seems wrong for me, you depicted that Method1() , Method2(), etc are executed by and not the trigger of transitions, etc. – Red Beard Nov 08 '13 at 08:57
0

I would recommend using a sequence diagram.

  1. Sequence diagrams allow for async calls of class/component methods. (or http requests handled by a thing represented as a method) This is really what you need. You would have the sequence diagram focus on their being multiple control flows to achieve a certain result.

  2. State diagrams are really quite low level and might map to this domain poorly. However, if you must, all of your methods/interactions must be recast as state changes, NOT, calls. A state machine moved between states, not methods and classes. So your state transitions would have to be "receive message of B with value A". Not what you are going for I suspect. It would not really help me understand your system.

  3. If you need to do this because you are doing MDA/Generative UML then expand on your question greatly. I am assuming this is a basic UML question, if not let me know and I can add more details.
Ted Johnson
  • 4,315
  • 3
  • 29
  • 31
  • Well, first, my UML skills are definitely sub-par, so please bear with me. I was asked to show the different states the application could be in, but I'm stuck trying to figure out how I can show that the state can change at any point to `Fail` and then change to the next state in the flow. For example, if I'm on state `A` and the state is changed to `Fail`, when I continue in the application the state can be changed to `B`, then `C`. – Matt R Nov 07 '13 at 16:02