22
Slide 1 Object-Oriented Software Systems Engineering – Chapter 7 Sequence and Collaboration Diagrams Chapter 7

7. sequence and collaboration diagrams

  • Upload
    apu

  • View
    4.434

  • Download
    2

Embed Size (px)

Citation preview

Page 1: 7. sequence and collaboration diagrams

Slide 1Object-Oriented Software Systems Engineering – Chapter 7

Sequence and Collaboration Diagrams

Chapter 7

Page 2: 7. sequence and collaboration diagrams

Slide 2Object-Oriented Software Systems Engineering – Chapter 7

Objectives

In this chapter we will: Review the different dynamic modelling

techniques Discuss different types of messages Discuss different types of events Introduce sequence and collaboration diagrams

Page 3: 7. sequence and collaboration diagrams

Slide 3Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling

Dynamics of a systemhow objects communicate and the effects of such

communicationhow objects collaborate through communication and how

objects change state

Dynamics of a system is described by four diagramsState SequenceCollaboration Activity

Interactioncommunication between objects in order to generate some

functiondescribed in sequence, collaboration and activity diagrams

Page 4: 7. sequence and collaboration diagrams

Slide 4Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling diagrams

State diagram -describeswhich states an object can have

behaviour in those states

what events cause the state to change

Sequence diagram - describes how objects interact and communicate with each other

primary focus is time

shows how a sequence of messages are sent and received between a set of objects in order to perform some function

Page 5: 7. sequence and collaboration diagrams

Slide 5Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling diagrams

Collaboration diagram - describes how objects interact

focus is on space - relationships between objects are shown

Activity diagram - describes activities and their order - another way of showing interactions

focus on work - when objects interact they also perform work in terms of activities

Page 6: 7. sequence and collaboration diagrams

Slide 6Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling - Messages

Messagea communication between objects that conveys

information has a sender and recipientis represented as an arrow denoting flow of control

Page 7: 7. sequence and collaboration diagrams

Slide 7Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling - Messages

Types of messagessimple

flat flow of control - control is passed without describing any details

synchronousnested flow of control - operation call

handling of the message is completed before the caller resumes execution

asynchronousthere is no explicit return to the caller

the sender continues to execute after sending the message without waiting for it to be handled

Page 8: 7. sequence and collaboration diagrams

Slide 8Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling

Use cases are elaborated in two stagesExpand the use-cases into sequence diagramsUse the sequence diagrams to produce finite state

machines

Page 9: 7. sequence and collaboration diagrams

Slide 9Object-Oriented Software Systems Engineering – Chapter 7

Events

Kinds of eventsreceipt of a call on an operation by another object

( message) the signal itself is an object-shown as an event-signature

on state transitionsreceipt of an explicit signal from another object

(message) the signal itself is an object- also shown as an event-

signature on state transitionsa condition becoming true

shown as a guard conditionpassage of a designed period of time

shown as a time expression

Page 10: 7. sequence and collaboration diagrams

Slide 10Object-Oriented Software Systems Engineering – Chapter 7

Events

Basic semantics about event labeled transitions events are triggers that activate state transitionsif an event can activate more then one transition only one

will be triggeredif en event occurs and guard is false then the event is

ignored (events are not stored)

Page 11: 7. sequence and collaboration diagrams

Slide 11Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling-Sequence Diagram

:Object A :Object B

:Actor A

destructor()

return

Objects lifeline

Asynchronous

messge

Focus of control

Synchronous

message

Simple message

XObject is destroyed

Page 12: 7. sequence and collaboration diagrams

Slide 12Object-Oriented Software Systems Engineering – Chapter 7

Sequence Diagram

Conditional branch

: A : B : C

[ x>0 ] doM()

[ x<=0 doN()]

*dialDigit(d)

: A : B

Loop

Page 13: 7. sequence and collaboration diagrams

Slide 13Object-Oriented Software Systems Engineering – Chapter 7

Sequence Diagram

To support conditional and looping constructs, the UML uses frames. Frames are regions or fragments of the diagrams; they have an operator or label (such as loop) and a guard (conditional clause).

The following table summarizes some common frame operators:

Frame Operator Meaning

alt Alternative fragment for mutual exclusion conditional logic expressed in the guards.

loop Loop fragment while guard is true.

opt Optional fragment that executes if guard is true.

par Parallel fragments that execute in parallel.

region Critical region within which only one thread can run.

Page 14: 7. sequence and collaboration diagrams

Slide 14Object-Oriented Software Systems Engineering – Chapter 7

Sequence Diagram Example

:floor panel

<<boundary>>

:ElevatorControl

<<control>>:floorSensor

<<boundary>>

:Elevator

Person on floor

Call(floorNumber)

moveUp(floorNumber)

arriveAt(floorNumber)

stop()

state moving up

state idle

state idle

Page 15: 7. sequence and collaboration diagrams

Slide 15Object-Oriented Software Systems Engineering – Chapter 7

Sequence Diagram Example

:floor panel

<<boundary>>

:ElevatorControl

<<control>>:floorSensor

<<boundary>>

:Elevator

Person on floor

Call(floorNumber)

moveDown(floorNumber)

arriveAt(floorNumber)

stop()

state moving down

state idle

state idle

Page 16: 7. sequence and collaboration diagrams

Slide 16Object-Oriented Software Systems Engineering – Chapter 7

Sequence Diagram Example

:ElevatorControl

<<control>>:floorSensor

<<boundary>>

:Elevator

[timer=time_out]/moveDown(firstfloor)

arriveAt(firstfloor)

stop()

state moving down to first floor

state on first floor

state idle

Page 17: 7. sequence and collaboration diagrams

Slide 17Object-Oriented Software Systems Engineering – Chapter 7

Dynamic Modelling - Collaboration Diagram

Show:network of collaborating objects

interactions - how messages are sent between objects

Used to illustrate execution ofa use casean operation

Focus on time

Page 18: 7. sequence and collaboration diagrams

Slide 18Object-Oriented Software Systems Engineering – Chapter 7

Collaboration Diagram

: Queue

: Computer : PrintServer

: Printer

: User

2: print( file)

5: printing

3: print( file )

4: printing

1: print( file )6: printing

Page 19: 7. sequence and collaboration diagrams

Slide 19Object-Oriented Software Systems Engineering – Chapter 7

Collaboration Diagram

: Queue

: Computer : PrintServer

: Printer

: User

2: print( file)

5: wait

3: store( file ) 4: stored1: print( file )6: wait

Page 20: 7. sequence and collaboration diagrams

Slide 20Object-Oriented Software Systems Engineering – Chapter 7

Collaboration Diagram for ElevatorControl

On further investigation ElevatorControl may need to be expanded into more classes

revisit sequence diagrams!

:Organiser:Queue

:Order

:Dispatcher

1: Call floor(number)1.1: *[all queues]:len=length(){return shortest}

1.2:Create()parameter

1.3:Invoke(job){join queue}

2: nextjob=get()

:ElevatorControl

Active object

own thread

of control

Page 21: 7. sequence and collaboration diagrams

Slide 21Object-Oriented Software Systems Engineering – Chapter 7

More about Interaction Diagrams

Different developers have different preferencestime-ordering or spatial

Interaction diagrams are good at showing collaboration between objects

They are not good at precise definition of the behaviour

They are at their best when the behaviour is simple To capture complex behaviour in a single diagram

use an activity diagram To look at the behaviour of a single object across

many use cases use a state diagram many use cases or many threads use an activity diagram

Page 22: 7. sequence and collaboration diagrams

Slide 22Object-Oriented Software Systems Engineering – Chapter 7

Summary

In this chapter we have: Reviewed the different dynamic modelling

techniques Discussed different types of messages Discussed different types of events Introduced sequence and collaboration diagrams