EddieIM
EddieIM

Reputation: 77

UML state for vending machine - branches dilemma?

I'm trying to draw UML state diagram for vending machine, maybe its basic but im a beginner and havent found the appropriate solution on internet

Task: - the vending machine receives 1,2 and 5 $, the price of drink is 2 $ - it dispenses the drink if enough money is entered and refunds change - machine has power on and power off)

I marked each state and transitions the numbers (STATES = s1,2 ..., TRANSITIONS = p1,2 ...), to make it easier to answer without drawing (e.g. "p1 is wrong, there should be written this" etc)

Here is my diagram: enter image description here

Questions:

  1. Does it eventually return to IDLE - which seems to me more logical - or it must go to the final state (rounded black point) as power off?

    Or can there be two final states, so the S5 goes to another final state?

  2. should it be after P3 or P4 maybe two branches?

    • maybe a new branch where the exact price amount is inserted (so there is no need for refund )
    • if so, where to put it?
  3. If I understand the principle, on the arrows there should be written in this form - correct?

    trigger event [condition if it exists] /
    action

  4. Is there any basic errors I made?

Thanks in advance, I appreciate any feedback.

Upvotes: 2

Views: 4463

Answers (1)

qwerty_so
qwerty_so

Reputation: 36323

  1. You can have as many finals as you need.
  2. I'd make Dispensing an optional state after Waiting (for the > case) while the = case will directly go to selection. Just from a logical perspective. Of course you can make machines do dispense and change in parallel. In that case you need to fork to Dispense and Refund.
  3. Correct
  4. You should model Power off as Signal which can be triggered at any time. The power can be disconnected at any time during the machine is running, not just when it's idle.

Upvotes: 1

Related Questions