Upload
felicity-manning
View
226
Download
5
Tags:
Embed Size (px)
Citation preview
1
Object OrientedAnalysis and Design
with UML
UNIT 3
2
Summary Unit 2...
UML Overview– Model systems using OO concepts
• Information systems, technical systems, system software, real time, distributed system,…
– UML is a modeling language– Based on the notion of views
• Use case, logical, component, concurrency, deployment view
3
Summary Unit 2...
– UML Diagrams
– Extensibility of the UML• Stereotypes, tagged values, constraints
Use-Case diagram Class diagram Object diagram State diagram Sequence diagram
Collaboration diagram Activity diagram Component diagram Deployment diagram
4
Summary Unit 2...
Static Modeling with UML– Use Case Diagrams
• to capture the functional requirements of a system
• informally stated in natural language
• focus on what the system is supposed to do
– Class Diagrams• A view of the system in terms of classes and relationships
• Behaviour as well as information in the system is modeled
– This static model of the system is built in a dynamic way !!
5
Use-Case Diagram
Customer Operator
Return Item
Print Daily Report
Change Item Data
6
Steps for Building a Use Case Model
Define the boundaries of the system Find the actors and use cases Define the relationships between the use cases Validate and verify the model
– Highly interactive with the end users !
– Should include discussions
Be Creative !
7
Class Diagram
8
Relationships Between Classes
An association is a connection between classes A generalization is a relationship between a more
general and a more specific element A dependency is a relationship between elements,
one independent another dependent A refinement is a relationship between two
descriptions of the same thing but at different levels of abstraction
9
Object Diagram
10
TheUnified
ModellingLanguage(continued)
UNIT 3
11
Unit 3 : Outline
Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams
12
Dynamic Modeling...
Describes what happens at run-time – Objects vs Classes
How do elements of static diagrams :– Cooperate to manage their tasks– Communicate with each other– Change their state– Provide the functionality of the system
Method outline and messages flow For capturing difficult to understand aspects
Complements
Static Diagrams
13
Dynamic Modeling.
Focus on communicating one aspect of a system’s dynamics
Model only those elements that are essential Provide detail consistent with the level of
abstraction Sometimes a piece of code says more than
lines, rectangles, ...
14
Different Dynamic Diagrams
Sequence Diagrams– Focus on time aspect of interaction and
communication
Collaboration Diagrams– Focus on space aspect of interaction and
communication
State Diagrams– Focus on state, behaviour and events
Activity Diagrams– Focus on work aspect of interaction and
communication
Inter-objectrelation
Intra-objectrelation
15
Unit 3 : Outline
Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams
16
State Diagram Symbols
17
Focus on
The possible states of the instances of a class
The possible transitions from one state to another one
The events firing transitions The operations which are executed within
states or during a transition Intra-objectrelation
18
Purpose of State diagrams
To document classes that have :– Clearly identifiable states
• State = {ongoing_behaviour, attributes, ...}
– Complex behaviour– Many events (signals)
19
Notation State Diagrams.
State
State Transition
Initial State
Final State
20
Parts of a State Diagram
Name
State Variables
Activities
State Box
State Transition
Initial State Final State
21
Example State Diagram
State Diagramfor the
Elevator Class
Onfirst floor
Movingup
IdleMovingdown
Moving tofirst floor
go up(floor)
Arriveat floor
Arriveat floor
Arriveat first floor
go up(floor)
go down(floor)
time-out
22
Parts of a State Box
Login
Login time = Current time
Entry/type “login”Exit/login (user name, password)Do/get user nameDo/get passwordHelp/display Help
State Name
State Variables
Activity
Actions
Atomic
Can be further decomposed
23
Login
Login time = Current time
Entry/type “login”Exit/login (user name, password)Do/get user nameDo/get passwordHelp/display Help
Activities Part of a State Box...
Describes the actions undertaken when the object is in a particular state
These actions are guided by events
Event-name argument-list ‘/’ action-expression
24
Activities Part of a State Box.
Standard events :
Entry / Action
Exit / Action
Do / Activity
event / Action
Action is executed whenentering the state
Action is executed whenleaving the state
Activity is executed, parametersare allowed
Event is handled withinthe state
25
State Transition Events…
Four kinds of events in UML :
ChangeEvent
A condition becoming true• shown as a guard condition on a state
transition
Receipt of a message• shown as an event signature on state
transitions
CallEvent
26
State Transition Events…
TimeEvent
A relative or absolute point in time• shown as a time expression on state
transition
SignalEvent
Signal Event : The receipt of a signal• <<error>> out_of_memory
• keyPressed, …
27
State Transition Events…
Messages vs Events
modeButton()Display
do/displaycurrent time
Set hours
do/displayhours
Set minutes
do/displayminutes
modeButton()
modeButton()
inc/minutes := minutes +1inc/hours := hours +1
DigitalWatch
modeButton()inc()
28
State Transition Labels (all optional)event-signature '[' guard-condition ']' '/'
action-expression '^' send-clause
event-signature = event-name '(' parameter ',',... ')'
Examples :– draw(f : Figure, c : Color)
– redraw
– redraw()
– print(invoice)
29
State Transition Labels…
event-signature '[' guard-condition ']' '/' action-expression '^' send-clause
Guard-condition = A boolean expression placed on a state transition
Examples :– [t = 15sec]
– [number of invoices > n]
– [withdrawal (amount) && balance >= amount ]
Guards are mutual exclusive
30
State Transition Labels…
event-signature '[' guard-condition ']' '/' action-expression '^' send-clause
Action-expression = Is executed when the transition fires
Examples :– increase () / n := n + 1
– add (n) / sum := sum + n
No nesting orrecursion allowed
31
State Transition Labels.
event-signature '[' guard-condition ']' '/' action-expression '^' send-clause
Send-clause = Explicit syntax for sending a message during a transition between two states
Examples :– ^ pen.set(color)
– [timer = Time-out] ^ self.go down (first floor)
32
Example : Digital Watch
modeButton()Display
do/displaycurrent time
Set hours
do/displayhours
Set minutes
do/displayminutes
modeButton()
modeButton()
inc/minutes := minutes +1 modulo 60
inc/hours := hours +1 modulo 24
33
Communication between Diagrams
Off On
Off On/Stop On/Play
On()
Off()
Off()
On()
Stop()
Play()
On() Off() Stop()Play()
Off()/Stop()
Stop()Play()
CD Player
Remote Control
34
Substates…
AND-STATES
States that may be true at the same time
Forward Backward
Running
Low speed High speed
35
Substates.
OR-STATES
States that may not be true at the same time
Forward Backward
Running
36
Unit 3 : Outline
Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams
37
Sequence diagram Symbols
Object 1 Object 2 Object 3
38
Focus on
The interaction and communication between objects
Specify the realization of an operation or use case
Message sequences Time aspect Cfr Collaboration diagram
39
Two Available Forms
Generic form– documents all possible alternatives in a scenario– conditions, loops, branches are possible– cfr class diagram
Instance form– documents one possible interaction– no conditions, loops, or branches– cfr object diagram
:Computer
C1:Computeror C1
40
Different Message Types
Only means of communication with objects are messages
Synchronous
Asynchronous
Simple
Synchronous withImmediate return
41
Notation Sequence Diagrams…
:Computer :PrintServer :PrinterPrint(ps-file)
Print(ps-file) [no queue]Print(ps-file)
42
Notation Sequence Diagrams.
:Computer
Print(ps-file)
[no queue]Print(ps-file)
Object
Message send
LifelineActivation
Return
Guard condition
43
Labels for Iteration
C1:C D1:D D2:Dmessage1()
message2()send message2 until …
message3()
44
Labels for Constraints
:Computer :PrintServer :PrinterPrint(ps-file)
Print(ps-file)
Print(ps-file)
a
b
b’{b’ – b < 1 sec}
{b - a < 5 sec}
•If PrinterServer receives a file, it should transmit this file to the Printer within 5 sec•Communicating the file from the PrinterServer to the Printer should take less than 1 sec
45
Object creation
:CustomerWindow
:Customer
NewCustomer(Data)
Customer(Data)
46
Object Destruction
:CustomerWindow :Customer
RemoveCustomer( )
DeleteCustomer( )
47
Unit 3 : Outline
Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams
48
Collaboration Diagram Symbols
49
Focus on
The interaction and communication between objects
Shows the static and dynamic relationships between objects – the context aspect
Space aspect(time is no dimension on its own)
Sequence indicated with numbers
50
Example Collaboration Diagram
:PrinterServer
[printer free] 1.1:Print(ps-file)
:Printer
:Computer
Print(ps-file)
1:Print(ps-file)
51
Message Flow Labels…
predecessor guard-condition sequence-expression return-value
predecessor = sequence-number ‘,’ … ‘/’
Indicates the assumed message flow before this message may happen
Examples :– 1,2,5 /
– 3 /
Only specify if not implicitly available !
52
Message Flow Labels…
guard-condition = ‘[‘ condition-clause ‘]’
predecessor guard-condition sequence-expression return-value
Examples :– 1,2,5 / [t = 15sec]
– [number of invoices > n]
– [withdrawal (amount) && balance >= amount]
53
Message Flow Labels.
predecessor guard-condition sequence-expression return-value
sequence-expression = [integer | name][recurrence] ‘:’
recurrence = ‘*’ ‘[‘ iteration-clause ‘]’
recurrence = ‘[‘ condition-clause ‘]’
Indicates that a message is a part of the actions undertaken in response to another message (referred to with the predecessor number)
Examples :– 1.1 *[x = 1..10]: doSomething()
– 1 [time-out]: display()
54
Role Names Role Names indicate how the objects know about each other
{Global}
{Local}
{Parameter}
{Self}
The object is known throughout the entire system
The object is knownlocally (temporary object)
The object is known since itwas passed as an argument
The object is referencing itself
{Association}The object is known as an
attribute (default)
55
Constraints Constraints indicate the objects’ existence during interaction
{New}
{Destroyed}
{Transient}
The object is created during the interaction
The object is destroyed during the interaction
The object will be created and destroyed
Nothing specifiedThe object was available before
the interaction took place
56
Example : Role names & Constraints
57
Unit 3 : Outline
Dynamic Modelling– State Diagrams– Sequence Diagrams– Collaboration Diagrams– Activity Diagrams
58
Activity Diagram Symbols
59
Focus on
Actions and their results How and when actions are taken What actions actually do Where actions take place (swimlanes) Work aspect Flowcharts featuring parallelism
60
Purpose of Activity Diagrams
To document :– The actions performed by an operation– The internal working of an object– Make parallelism explicit– A use case
• How is it performed in terms of actions and states?
– Workflow
61
Notation Activity Diagrams.
Action/Activity
Object Flow
Start State End State
Control Flow
Concurrency Decision State
62
Example Activity Diagram
Action/Activity
Decision
Initial event
Control Flow(Same label notation as
transitions State Diagram)
ShowMessageBox“Disk full” on
screen
ShowMessageBox“Printing” on
screen
RemoveMessageBox
CreatePostscript
file
[disk full]
[free disk space]
^Printer.print(file)
printFile()
63
Control Flow
Indicates the order of actions and activities Represented by transition arrows No events on arrow :
– As soon as the execution of the predecessor is finished, the successor is started
Guard conditions are allowed
64
Decision State / Concurrency
Decision State– Makes alternative sequences explicit
– Complex decisions can be visualized by decision trees
– Outgoing transitions must have mutually exclusive guards
Concurrency– Fork/Join denotes starting/ending point
of concurrent execution
– Combined with guard conditions it formsan alternative to the decision state
65
Swimlanes
Objects that are
responsible can be
assigned to actions
and activities
Initiate
MeasuringUpdatingDisplayer
Sampler.Run(channel, frequency)
Displayer Sampler
66
Course Overview.
UML Diagrams Use-Case diagram Class diagram Object diagram State diagram Sequence diagram
Collaboration diagram Activity diagram Component diagram Deployment diagram
Last Unit