OOSE Chapter 8
OOSE Chapter 8
OOSE Chapter 8
Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Sequence diagrams
A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task The objects are arranged horizontally across the diagram. An actor that initiates the interaction is often shown on the left. The vertical dimension represents time. A vertical line, called a lifeline, is attached to each object or actor. The lifeline becomes a broad box, called an activation box during the live activation period. A message is represented as an arrow between activation boxes of the sender and receiver. A message is labelled and can have an argument list and a return value.
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
10
Lethbridge/Laganire 2005
11
Communication diagrams
Communication diagrams emphasise how the objects collaborate in order to realize an interaction A communication diagram is a graph with the objects as the vertices. Communication links are added between objects Messages are attached to these links. Shown as arrows labelled with the message name Time ordering is indicated by prefixing the message with some numbering scheme.
Lethbridge/Laganire 2005
12
Lethbridge/Laganire 2005
13
Communication links
A communication link can exist between two objects whenever it is possible for one object to send a message to the other one. Several situations can make this message exchange possible: 1. The classes of the two objects have an association between them.
- This is the most common case. - If all messages are sent in the same direction, then probably the association can be made unidirectional.
Lethbridge/Laganire 2005
14
3. A reference to the receiving object has been received as a parameter of the sending method.
- The stereotype is parameter or [P].
Lethbridge/Laganire 2005
15
Lethbridge/Laganire 2005
16
Lethbridge/Laganire 2005
17
Lethbridge/Laganire 2005
18
Lethbridge/Laganire 2005
19
20
Lethbridge/Laganire 2005
21
States
At any given point in time, the system is in one state. It will remain in this state until an event occurs that causes it to change state. A state is represented by a rounded rectangle containing the name of the state. Special states: A black circle represents the start state A circle with a ring around it represents an end state
Lethbridge/Laganire 2005
22
Transitions
A transition represents a change of state in response to an event. It is considered to occur instantaneously. The label on each transition is the event that causes the change of state.
Lethbridge/Laganire 2005
23
Lethbridge/Laganire 2005
24
Lethbridge/Laganire 2005
25
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
27
Lethbridge/Laganire 2005
28
Lethbridge/Laganire 2005
29
Lethbridge/Laganire 2005
30
Lethbridge/Laganire 2005
31
Lethbridge/Laganire 2005
32
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
34
Representing concurrency
Concurrency is shown using forks, joins and rendezvous. A fork has one incoming transition and multiple outgoing transitions.
- The execution splits into two concurrent threads.
Lethbridge/Laganire 2005
35
Representing concurrency
A join has multiple incoming transitions and one outgoing transition.
- The outgoing transition will be taken when all incoming transitions have occurred. - The incoming transitions must be triggered in separate threads. - If one incoming transition occurs, a wait condition occurs at the join until the other transitions occur.
Lethbridge/Laganire 2005
36
Swimlanes
Activity diagrams are most often associated with several classes. The partition of activities among the existing classes can be explicitly shown using swimlanes.
Lethbridge/Laganire 2005
37
Lethbridge/Laganire 2005
38
39
Example
Lethbridge/Laganire 2005
40
Cancelled:
closedOrCancelled == true && registrationList.size() == 0
Lethbridge/Laganire 2005
41
Lethbridge/Laganire 2005
42
Lethbridge/Laganire 2005
43
public void openRegistration() { if(!closedOrCanceled) // must be in 'Planned' state { open = true; // to 'OpenNotEnoughStudents' state } }
Lethbridge/Laganire 2005
44
45
46
Lethbridge/Laganire 2005
47
Drawing different diagrams that capture related, but distinct, information will often highlight problems.
Lethbridge/Laganire 2005
48