View
337
Download
0
Category
Tags:
Preview:
Citation preview
Dynamic Models
Sequence DiagramsCollaboration DiagramsActivity 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.
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
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.
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).
Message Passing
How are messages passed between objects?
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.
State Diagram
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.
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.
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
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)
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.
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]
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
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.
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
Sequence Diagram
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.
Sequence Diagram
:Control Unit :Sensor Intruder
HouseHolder
Switch On
Valid Access Code
Entry
Police
Person detected
:TimerStart
Invalid Access Code
TimeoutNotify
activation
lifeline
X
Sequence Diagram Example
Collaboration Diagram
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.
Collaboration Diagram
Consider the Class Diagram for the burglar alarm scenario:
Control Unit
Timer
Sensormonitors
signals1 1..*
Uses
1
1..*
Collaboration Diagram Example
:Control Unit
:Timer
:Sensor
InfraRed1:person_detected()
1.1:Start()
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.
Activity Diagram
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.
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
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:
Activity Diagram
Consistency!!
• Ensure that all dynamic models are consistent with each other.
• Ensure that all dynamic models can be realised from the static models.
Recommended