11.4 Modeling Dynamic Characteristics


11.4 Modeling Dynamic Characteristics

In addition to the UML diagrams that describe the static characteristics of an application, UML includes a group of diagrams to describe the dynamic characteristics or behavior. These diagrams describe the individual behavior (the ordering of events and activities) of the objects and interactions among objects in an application. The sequence and collaboration diagrams describe the message communication among objects. The state diagrams show more detailed behavior of an object.

11.4.1 Collaboration Diagrams

The UML collaboration diagram describes the general interactions among objects. The diagram shows the overall connectivity of the objects in the application. This gives a complete high-level view of the overall communication architecture of the system. A collaboration diagram includes the notation for showing the direction of the messages by using arrows and the sequence of these messages by numbering them.

Collaboration diagrams can also be used to describe additional details of the interaction among objects. As explained before, the UML notation for an object is the rectangle. The label is written as follows: the name of the object, a colon, and the name of the class to which it belongs. The complete label must be underlined. The name of the object is optional.

To describe the interaction among the object of class Person with the two objects of class Ball, a simple collaboration diagram is drawn. Figure 11.7 shows a collaboration diagram with the three objects. In this example, an object of class Person invokes the move operation of the object of class Ball by sending a message to the first object of class Ball. As a result of this message the object of class Ball performs its move operation. The object of class Person also sends a message to the other object of class Ball, by invoking its show_color operation.

click to expand
Figure 11.7: Collaboration diagram with three objects.

11.4.2 Sequence Diagrams

These UML diagrams describe the interaction among objects arranged in a time sequence. The objects involved in the interaction are shown as rectangles arranged in a horizontal manner. In addition to the objects involved in the interaction, these diagrams have two important components: the lifelines of each object and the messages from one object to another object. The lifelines are shown as vertical dashed lines starting from each object (top). These vertical lines represent the object existence during the interaction. Each message is shown as a horizontal arrow from one object to another. Each message is labeled with a message name. Figure 11.8 shows a sequence diagram with three objects, one of class Person and two objects of class Ball.

click to expand
Figure 11.8: A sequence diagram with three objects.

11.4.3 State Diagrams

The state diagram describes the sequence of states that an object performs in response to events or messages from other objects. Each state diagram describes the behavior of only one object. The state of an object is determined by the values of its attributes. The object carries out an activity while it is in a state. A transition is the change from one state to the next state as a result of an event or message.

The states are represented as rectangles with rounded corners, with the name of the state inside the rectangle. The transitions are represented as arrows connecting two states: the source state and the destination state. The label of the transition is the name of the message or event that triggered the transition. The transition may also include a list of arguments in parentheses for the event and an action or activity that the object must carry out as a result of the transition.

Usually, a black dot indicates the start of the transitions of an object. This transition leads to the first state. The last state is shown as the state with an arrow pointing to a black dot inside a circle. This corresponds to the last transition of the object. Figure 11.9 shows a state diagram for an object of class Ball.

click to expand
Figure 11.9: A state diagram for objects of class Ball.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net