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?
- A. It forces the state machine to skip the Paid state entirely
- 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
- C. It has no effect; guards in UML state machines are purely documentation
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- In a class diagram, Student has an association to Course with multiplicity 0.. on the Student side and 0.. on the Course side…
- An activity diagram shows a fork bar splitting one flow into two concurrent activities (ValidateAddress and ChargeCard), which later…
- A class diagram shows Shape as an abstract class with an italicized name and an italicized method + area(): double, and Circle, Square as…
- In a sequence diagram, a long thin rectangle drawn on top of a lifeline is called an activation bar (execution occurrence). What does its…
- A class diagram shows Employee with attribute - salary: double and operation + getSalary(): double. What do the leading - and + symbols…
- A sequence diagram shows a loop combined fragment labelled loop [for each item in cart] wrapping a single message validateItem(item) sent…