Jolzal
Jolzal

Reputation: 597

Sequence Diagram UML if else based on decision

Is it okay having if else inside sequence diagram based on the actor decision, in example if actor think the price is reasonable enough then execute if, and if it is not reasonable price then execute else like this :

enter image description here

Thankyou

Upvotes: 1

Views: 555

Answers (1)

Christophe
Christophe

Reputation: 73500

Yes, but...

The combined fragment alt may have several operands separated by horizontal lines and guarded, either by an interaction constraint like [Reasonable price], or by an [else]. If we go by the book:

An InteractionConstraint is shown in square brackets covering the lifeline where the first event occurrence will occur, positioned above that event (...).

This graphical instruction is important (even if I'm the first to forget about it). Accordingly, [Reasonable price] should cover the lifeline of your actor. In practice, if you don't, your readers will do the mapping implicitly, but the diagram might be more ambiguous.

Why?

It is important to realize that this graphical instruction hides a deeper reality: in your case, if it's the actor who shall take initiative of beginning the relevant alt operand and send some message, then the actor should be able to evaluate if [Reasonable price] applies.

We should keep here in mind that the sequence diagram describes the possible path of execution ("traces" in UML jargon, because path of execution means too many things to too many people) of an interaction:

Interactions are units of behavior of an enclosing Classifier.

The semantics of an Interaction is given as a pair of sets of traces. The two trace sets represent valid traces and invalid traces.

A trace is a sequence of event occurrences (...)

And since the sequence diagram is made of interactions between its lifelines, the guards should be evaluated based on the available knowledge, i.e. the knowledge of the lifeline that starts the operand (and in some cases knowledge of the enclosing classifier).

This is not an explicit UML requirement, but a logical deduction considering the principle of encapsulation and the potential visibility constraints. It makes the model more useful and avoids irrealistic expectations. By antagony, what would be the leaning of a guard [beautiful weather] if none of the participating lifeline would have a window to look at the sky and see what the weather looks like?

Conclusion

If your actor has a lifeline in the diagram, make sure the guard covers it.

If your actor has no lifeline in the diagram, this guard would still be syntactically correct. But ask yourself which of the participant of the interaction could at the same time know the price and determine what is a reasonable price.

Upvotes: 3

Related Questions