Page 813 - Introduction to Programming with Java: A Problem Solving Approach
P. 813

                Apago PDF Enhancer
activity symbol is not supposed to represent code itself. It’s supposed to represent the code’s “activity.” Thus, it’s appropriate to repeat an activity symbol that represents a complete method when you call that method more than once.
When there is more than one class and perhaps several objects, UML suggests that you organize the activities into columns, such that all the activities for any one class or object are in a single column dedi- cated to that class or object. UML calls these separate columns swimlanes. Vertical dashed lines separate adjacent swimlanes. At the top of the diagram over appropriate swimlane(s), write the class name for the lane or lanes below. Precede each class name with a colon and put it into a separate rectangular box. When you mean to instantiate an object, write that object’s name followed by a colon and its class name. Underline it and put it into a separate rectangular box located just after the activity that creates it.
Figure A7.2 shows the UML activity diagram for the Mouse2 program defined in Figures 6.14 and 6.15. Notice how each activity (oval) is aligned under its own class and (if applicable) its own object. Activities for the lowest-level objects typically represent complete methods. Activities for higher level objects typically represent code fragments. Solid black arrows represent control flow. They always go from one activity to another activity. Notice how the control flow moves continuously downward.
Dashed black arrows represent data flow associated with each activity. They go from an activity to an object or from an object to an activity but never from one activity to another activity. These dashed lines are often omitted to reduce clutter, but you can see how they help to show what the activities do. For example, notice how the dashed line from the “mickey : Mouse2” object to the “print mickey’s attributes” activity helps explain what happens and allows us to suppress the two “get” method calls embedded in the print statement:
System.out.printf("Age = %d, weight = %.3f\n",
mickey.getAge(), mickey.getWeight());
Appendix 7 UML Diagrams 779
    guard
  [count > 100]
[count < = 100]
print “Happy birthday! set count to count + 1
transition
activity
set count to 1
             Figure A7.1 UML activity diagram for Happy Birthday algorithm in Figure 2.9
Or you could use a single activity symbol to represent all the actions performed by a complete method. An
⎫ ⎪ ⎪ ⎬ ⎪ ⎪ ⎭

















































































   811   812   813   814   815