dynamic models sequence diagrams collaboration diagrams activity diagrams

32
Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Upload: arthur-skinner

Post on 18-Jan-2016

334 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Dynamic Models

Sequence DiagramsCollaboration DiagramsActivity Diagrams

Page 2: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Dynamic Modelling

Static ModelExpress the static structure of a system including the classes, objects, and their relationships.

Dynamic ModelExpress the behaviour of a system to demonstrate how the object interact dynamically at different times during the execution of the system.– control information– the sequences of events, – States and operations that occur within a system of objects, – usually involving the time dimension.

Page 3: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Dynamic Modelling

• Objects communicate with each other by sending messages to each other.

• A message is an operation call that one object invokes in another object.

• The way objects communicate and the effects of the communication are referred to as the dynamics of the system.– How objects collaborate through communication– How objects change state

Page 4: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

UML Dynamic Models

• Communication among objects is called interaction.

• Can be described by 3 types of diagram:– Sequence Diagram: Shows how a sequence of

messages are sent and received between objects. Focus is time.

– Collaboration Diagram: Focus on the relationships between objects.

– Activity Diagram: describes the activities of objects and their order.

Page 5: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

UML Dynamic Models

• There is another dynamic model in UML that examines the interactions between objects from a single object’s point of view.

• State Diagram: describes which states an object can have during its lifecycle, and the behaviour in those states, along with what events cause the state to change; for example, and invoice can be paid (state paid) or unpaid (state unpaid).

Page 6: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Message Passing

How are messages passed between objects?

Page 7: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Message Types

Synchronous - invoked operation completes before controlreturns to caller.

Asynchronous - caller continues processing while call is outstanding.

Simple - Shows control passing between objects but withoutindicating precise mechanism involved.

Page 8: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

State Diagram

Page 9: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

State Diagram

• All objects have a state.

• The state is the result of the previous activity performed by the object.

• The state is determined by the value of its attributes and links to other objects.

• An object changes state when something happens – called an event.

Page 10: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

State Diagram

• Show how objects react to events and how they change their internal state.

• Has a starting point and can have several end points.

Page 11: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Components of a State Diagram

Event something that happens at a point in time. An event has no duration. For

example, received messages, time-outs, error exceptions.

State an abstraction of the attribute values and links of an object

Activity an operation that takes time to perform closely associated with a state

Action an operation performed on a state change

Page 12: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

State Diagram

State 2 . . .

State 1do/activity 1

event [condition] /action

name ofevent whichcauses transition

an action that isperformed when the event occurs

a pre-condition beforea transition occurs

Starting point An end point(there can be several

end points)

Page 13: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Relationships between State Diagram & Class Diagram

• A state diagram relates to ONE class within a class diagram. The received events are often messages that will have originated at one of the other classes with which the class in question has a relationship.

• Events are basically received messages and are therefore handled by a receiving class operation.

• Actions - happening upon a state transition - are usually class operations that may result in a message being sent to another object.

• Activities - happening within a particular class state - are usually class operations.

Page 14: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

A State Diagram Example

Passive

Monitordo/ checkdetectors

Detecteddo/ ring bellflash lights

Alarm System

access code typed inIntruder alert/ phone police

correct access code typed in

[30 seconds passed]

Page 15: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Another Example

Do/moving tofloor

On first floor

idleMoving to first

floor

Go up (floor)

Arrived

Arrived

Go

up (

floor

)

Go down (floor)

arrived

Time-out

Moving up

Moving Down

Do/moving tofloor

Page 16: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Nested State Diagram

•State diagrams for an object may be nested, allowing the control mechanism to be viewed at different levels of abstraction.

•A nested state diagram is a form of generalisation on states.

Page 17: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Nested State Diagram

OFF

intruderdetected

activesensing

passive sensing

Alarm System Controller

on

power onpower off

code detect

code

Alarmtime out

On

State diagram of alarm system controller with generalisation

Page 18: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Sequence Diagram

Page 19: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Sequence Diagram

• Illustrate how objects interact with each other.

• Has two axis: – Vertical shows time– Horizontal shows objects

• Reveals the interactions for a specific scenario.

Page 20: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Sequence Diagram

:Control Unit :Sensor Intruder

HouseHolder

Switch On

Valid Access Code

Entry

Police

Person detected

:TimerStart

Invalid Access Code

TimeoutNotify

activation

lifeline

X

Page 21: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Sequence Diagram Example

Page 22: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Collaboration Diagram

Page 23: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Collaboration Diagram

• Like the sequence diagram the collaboration diagram show the interactions between objects.

• The sequence focuses on time, while the collaboration diagram focuses on ‘space’ (meaning the interactions and links between collaborating objects).

• Use a collaboration diagram when the objects and their links facilitate understanding the interaction.

• Use a sequence diagram when only the sequence needs to be shown.

Page 24: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Collaboration Diagram

Consider the Class Diagram for the burglar alarm scenario:

Control Unit

Timer

Sensormonitors

signals1 1..*

Uses

1

1..*

Page 25: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Collaboration Diagram Example

:Control Unit

:Timer

:Sensor

InfraRed1:person_detected()

1.1:Start()

Page 26: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Sequence & Collaboration Diagrams

• Sequence diagram emphasises Time.

• Collaboration diagram emphasises Interaction superimposed on links.

– Clearer connection with the UML class diagram

• Both diagram types can be used to depict the execution of a Use-case.

Page 27: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Activity Diagram

Page 28: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

UML Activity Diagram

• Capture actions and their results.• Can place actions in swimlanes. A swimlane

groups activities, with respect to who is responsible for them.

• Can be used to:– Capture work that will be performed when an

operation is executing.– Show how a set of related actions may be performed

an how they will affect objects around them.– Show how an instance of a use case may be

performed– Show how a business works in terms of workers

(actors), workflows, organisations, and objects.

Page 29: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Activity Diagram Notation

An identified action or activity

A decision branch

An object either input to, or output from an action

Signal Receipt - for receiving info. (usually from an object)

Signal Send - denoting a signal being sent to an object

Page 30: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Activity Diagram Example

Determine Closing Date and Interview

Dates

Job Start Date

Manager

[sufficient time]

[insufficient time]Notify

Job Spec.

Advert[Create]

Consider the recruitment Use-case introduced earlier in the course. The recruitment process could be described by the following activity diagram:

Page 31: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Activity Diagram

Page 32: Dynamic Models Sequence Diagrams Collaboration Diagrams Activity Diagrams

Consistency!!

• Ensure that all dynamic models are consistent with each other.

• Ensure that all dynamic models can be realised from the static models.