CS FundamentalsHardProduct company interview · GATE level

A state machine diagram for an Order has states New, Paid and Shipped, with a transition from New to Paid labelled 'payment confirmed / sendReceipt()', and a self-transition on Paid labelled 'itemAdded [not yet shipped] / recalculateTotal()'. What does the self-transition's guard condition do?

  1. A. It forces the state machine to skip the Paid state entirely
  2. B. It restricts the transition so recalculateTotal() only runs when the order has not yet shipped, even though an itemAdded event could in principle arrive at other times
  3. C. It has no effect; guards in UML state machines are purely documentation
  4. D. It means the transition fires twice for every itemAdded event

Correct answer: B. It restricts the transition so recalculateTotal() only runs when the order has not yet shipped, even though an itemAdded event could in principle arrive at other times

A guard condition (in square brackets) is evaluated when the triggering event occurs; the transition (and its effect, recalculateTotal()) fires only if the guard is true at that moment, letting the same event be handled differently depending on context.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic