UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory UML Weekend Crash Course™ - To Parent Directory

crnarupa.singidunum.ac.rs
from crnarupa.singidunum.ac.rs More from this publisher
01.01.2015 Views

Session 14—Modeling the Functional View: The Activity Diagram 151 Taking a Look at Activity Diagram Notation In this section, I give you a quick tour of the notation. A lot of this may be familiar if you’ve used flowcharts, so feel free to skim over the session until you spot something that looks new. Activities and transitions An activity is a step in a process where some work is getting done. It can be a calculation, finding some data, manipulating information, or verifying data. The activity is represented by a rounded rectangle containing freeform text. An Activity diagram is a series of activities linked by transitions, arrows connecting each activity. Typically, the transition takes place because the activity is completed. For example, you’re currently in the activity “reading a page.” When you finish this activity, you switch to the activity “turning page.” When you are done turning the page . . . well, you get the idea. Figure 14-1 shows this idea graphically. Read a page Turn a page Figure 14-1 Activities and transitions This notation starts to show the overlap between the Activity diagram and the Statechart diagram. In fact, the Activity diagram is a subset of the Statechart diagram. Each Activity is an action state where the object is busy doing something (as opposed to waiting). Each transition is a change in state, a change from one activity or active state to the next. So as you learn the Activity diagram, you are well on your way toward understanding the Statechart diagram as well. You’ll see and use the Statechart diagram in Sessions 20 through 23. Tip You may sometimes see the word “Do:” preceding the name of an activity. This is a common and valid notation to distinguish an activity from other state-related behaviors defined by the UML. Guard condition Sometimes the transition should only be used when certain things have happened. A guard condition can be assigned to a transition to restrict use of the transition. Place the condition within square brackets somewhere near the transition arrow. The condition must test true before you may follow the associated transition to the next activity. The Activity diagram segment in Figure 14-2 tells you that you can’t leave the table when you’ve finished your dinner unless you have finished your vegetables.

152 Saturday Afternoon Eat your dinner [Finished your vegetables] Leave the table Figure 14-2 A guard condition on a transition Decisions The Activity diagram diamond is a decision icon, just as it is in flowcharts. In either diagram, one arrow exits the diamond for each possible value of the tested condition. The decision may be as simple as a true/false test (for example, the left-hand illustration in Figure 14-3 asks, “Are there sufficient funds in the customer’s account to cover the withdrawal”). The decision may involve a choice between a set of options. For example, the right-hand illustration in Figure 14-3 asks, “Would you like chocolate, vanilla, strawberry, or rocky road ice cream” Each option is identified using a guard condition. Each guard condition must be mutually exclusive so that only one option is possible at any decision point. The guard is placed on the transition that shows the direction that the logic follows if that condition is true. If you write code, then you have probably used a case statement to handle this same type of problem. [sufficient funds] [insufficient funds] [chose chocolate] [chose vanilla] [chose strawberry] [chose rocky road] Give the customer the money Shake your finger at the customer Serve up chocolate ice cream Serve up vanilla ice cream Serve up strawberry ice cream Serve up rocky road ice cream Figure 14-3 Making a decision Because every choice at a decision point is modeled with a guard condition, it is possible to use the conditional logic on transitions leaving an activity as well. For example, in Figure 14-4 the activity of computing the new account balance reveals whether the account is overdrawn. All the information needed to make the choice is provided by the activity. To show the choices resulting from an activity, simply model the transitions exiting the activity, each with a different guard condition.

Session 14—Modeling the Functional View: The Activity Diagram 151<br />

Taking a Look at Activity Diagram Notation<br />

In this section, I give you a quick tour of the notation. A lot of this may be familiar if<br />

you’ve used flowcharts, so feel free to skim over the session until you spot something that<br />

looks new.<br />

Activities and transitions<br />

An activity is a step in a process where some work is getting done. It can be a calculation,<br />

finding some data, manipulating information, or verifying data. The activity is represented<br />

by a rounded rectangle containing freeform text. An Activity diagram is a series of activities<br />

linked by transitions, arrows connecting each activity. Typically, the transition takes place<br />

because the activity is completed. For example, you’re currently in the activity “reading a<br />

page.” When you finish this activity, you switch to the activity “turning page.” When you are<br />

done turning the page . . . well, you get the idea. Figure 14-1 shows this idea graphically.<br />

Read a page<br />

Turn a page<br />

Figure 14-1 Activities and transitions<br />

This notation starts to show the overlap between the Activity diagram and the Statechart<br />

diagram. In fact, the Activity diagram is a subset of the Statechart diagram. Each Activity is<br />

an action state where the object is busy doing something (as opposed to waiting). Each transition<br />

is a change in state, a change from one activity or active state to the next. So as you<br />

learn the Activity diagram, you are well on your way toward understanding the Statechart<br />

diagram as well. You’ll see and use the Statechart diagram in Sessions 20 through 23.<br />

Tip<br />

You may sometimes see the word “Do:” preceding the name of an activity.<br />

This is a common and valid notation to distinguish an activity from other<br />

state-related behaviors defined by the <strong>UML</strong>.<br />

Guard condition<br />

Sometimes the transition should only be used when certain things have happened. A guard<br />

condition can be assigned to a transition to restrict use of the transition. Place the condition<br />

within square brackets somewhere near the transition arrow. The condition must test<br />

true before you may follow the associated transition to the next activity. The Activity diagram<br />

segment in Figure 14-2 tells you that you can’t leave the table when you’ve finished<br />

your dinner unless you have finished your vegetables.

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

Saved successfully!

Ooh no, something went wrong!