01.01.2015 Views

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

152<br />

Saturday Afternoon<br />

Eat your dinner<br />

[Finished your vegetables]<br />

Leave the table<br />

Figure 14-2<br />

A guard condition on a transition<br />

Decisions<br />

The Activity diagram diamond is a decision icon, just as it is in flowcharts. In either diagram,<br />

one arrow exits the diamond for each possible value of the tested condition. The decision<br />

may be as simple as a true/false test (for example, the left-hand illustration in Figure<br />

14-3 asks, “Are there sufficient funds in the customer’s account to cover the withdrawal”).<br />

The decision may involve a choice between a set of options. For example, the<br />

right-hand illustration in Figure 14-3 asks, “Would you like chocolate, vanilla, strawberry, or<br />

rocky road ice cream”<br />

Each option is identified using a guard condition. Each guard condition must be mutually<br />

exclusive so that only one option is possible at any decision point. The guard is placed on<br />

the transition that shows the direction that the logic follows if that condition is true. If<br />

you write code, then you have probably used a case statement to handle this same type of<br />

problem.<br />

[sufficient<br />

funds]<br />

[insufficient<br />

funds]<br />

[chose<br />

chocolate]<br />

[chose<br />

vanilla]<br />

[chose<br />

strawberry]<br />

[chose<br />

rocky road]<br />

Give the<br />

customer the<br />

money<br />

Shake your<br />

finger at the<br />

customer<br />

Serve up<br />

chocolate<br />

ice cream<br />

Serve up<br />

vanilla<br />

ice cream<br />

Serve up<br />

strawberry<br />

ice cream<br />

Serve up<br />

rocky road<br />

ice cream<br />

Figure 14-3 Making a decision<br />

Because every choice at a decision point is modeled with a guard condition, it is possible<br />

to use the conditional logic on transitions leaving an activity as well. For example, in Figure<br />

14-4 the activity of computing the new account balance reveals whether the account is<br />

overdrawn. All the information needed to make the choice is provided by the activity. <strong>To</strong><br />

show the choices resulting from an activity, simply model the transitions exiting the activity,<br />

each with a different guard condition.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!