Other Aspects of UML Richard Hopkins UML for Use Cases

advertisement
Other Aspects of UML
Richard Hopkins
rph@nesc.ac.uk
UML for Use Cases
NeSC, Edinburgh, Jan 5/6 2006
OUTLINE
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
2
Deployment of Components
Component (here) –
“a distributable piece of an implementation of a
system, including S/W code , but also including
business documents etc. in a human system”
A WSDL definition could usefully viewed as a
component
Deployment Diagram shows –
Hardware items and physical communication links
Location of components on H/W items
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
3
Deployment
User’s:PC
<<Internet>>
B:Browser
Univ:Server
P:Portal
<<LAN>>
Clerk’s:PC
L:Library
System
Shows Hardware Structure
Shows an example of intended deployment
Shows component dependencies –
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
4
STATE DIAGRAMS
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
5
State (chart) Diagrams
In Wings
On Loan
Statechart
For Copy
Class
On Shelf
In Bindery
Reserved on Shelf
Reserved In Bindery
Based on finite state machine concept
Identifying all the different states a discrete-state system
can be in
Identify all the possible transitions between states
Generic life-history of a type of entity
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
6
State (chart) Diagrams
In Wings
On Loan
Statechart
For Copy
Class
On Shelf
In Bindery
Reserved on Shelf
Reserved In Bindery
Has full power of a programming language
trigger on an arc – e,g receipt of a message
guard on an arc – condition on moving to that state
actions on an arc – actions done in moving to next state
entry / exit actions – actions done whenever enter/leave a
state
Compound states
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
7
COLLABORATION DIAGRAMS
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
8
Basic Collaboration Diagrams
theUser: User
Book
Borrower
theCopy: Copy
suspended: No
theBook: Book
To show an example of message passing interaction between
objects
Links - instances of class associations
Actors/Objects –
Show name and type
Can show values for objects where useful
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
9
With Messages
1: borrow (theCopy)
Book
Borrower
theUser: User
suspended: No
1.2: borrow ()
theCopy: Copy
1.2.1: borrowed()
1.3: borrowStatus
1.1: okToBorrow
theBook: Book
Messages – actual messages passed,
Show operation invoked at destination
Use structured sequence numbering scheme


1.2 – second message produced as a result of receiving
message 1
1.2.1 - first message produced as a result of receiving message
1.2
Use self-messages to indicate internal condition testing
Different perspective on a sequence diagram
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
10
CUSTOMISATION
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
11
Stereotypes
Adding extra classification to model elements
Either Pre-defined
Or Model-specific
Already seen some stereotypes
Return <<include>>
Overdue
Copy
<<extend>>
Pay fine
<<Internet>>
User’s:PC
Defer fine
<<LAN>>
Univ:Server
Clerk’s:PC
Use Case Diag.
Pre-defined
Deployment Diag.
Model-specific
<<stereotype name>> - written “near” the element
Can use for any element – icon, line, operation, …
Can define a new icon for a particular stereotype –
Developing specialised language
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
12
Properties
Book
Title : String
{isQuery = true} copiesOnShelf() : Integer
{author = Richard,
reviewer = David}
{isQuery} getISBN() : ISBN
A model element can have a value for a property –
{isQuery = true}
Boolean property values can be written
{X} rather than {X = true}
A way of recording design information
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
13
Pre-defined Properties
documentation=
Applies to everything
location =
Applies to most things;
Value is typically a deployment diagram node or component
persistence =
Applies to: class, association, attribute
Whether value survives system re-start
Value usually – Persistent / Transient
semantics =
Applies to class and operation
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
14
PACKAGES
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
15
Packages
User
Student
loaned to
Staff
loaned
to
Item
Copy
Is copy
of
Book
is part
of
contains
Journal
Article
wants print-off of
User
To do with items
items
Student
Dependency on
something in
the package
Staff
Group collection of elements into a named package
which can be included in diagrams which depend on the
package
NOT JUST CLASSES Any collection of elements ; Used in any type of diagram
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
16
Packages
Possible reasons for use
Just to hide irrelevant detail
To reflect implementation team structure
Factor the design process
Create different namespaces

Names must be unique within package

Full name is package-name::element-name
Control visibility –
and thus reduce dependencies
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
17
SEQUENCE DIAGRAMS
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
18
Sequence Diagrams
Book
Borrower
theUser: User
1: borrow(theCopy)
theCopy: Copy
theBook: Book
t
i
m
e
1.1: okToBorrow
1.2: borrow()
1.2.1: borrowed()
borrowStatus
Sending a message
Object existence lifeline
Period of activation
Replies – all
shown
Uses structured sequence numbering
1
BookBorrower invokes the use case -activates corresponding theUser object
1.1 theUser checks whether this is OK – self message
1.2 theUser tells theCopy object that it is now borrowed – it changes its state
1.2.1. theCopy tells theBook that it has been borrowed –
it reduces its count of available copies
Reply - theUser confirms success to BookBorrower – the only “significant reply”
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
19
Creation and Deletion
Librarian
CreationLifeline starts
As a result
of message
theCatalogue:Catalogue
registerBook(theBook)
createBook(theBook)
theBook: Book
Librarian
theCatalogue:Catalogue
theBook: Book
Deletion Lifeline ends
Marked by a cross
removeBook(theBook)
destroy()
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
20
Synchronous Messages
Librarian
theAccounts:Accounts
mailer: MailingLIst
loseUser
owesMoney
loseUser
X
Synchronous – the sender suspends until receives reply
Explicit reply to a synchronous message
Because synchronous, can omit the reply
Omit this one because no useful information
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
21
Asynchronous Messages
Librarian
theAccounts:Accounts
mailer: MailingLIst
loseUser
loseUser
owesMoney
Asynchronous – the sender retains control and can send and receive
further messages
other versions of arrow heads are also used
Unspecified (simple) – could be synchronous or asynchronous
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
22
Conditionals
Librarian
BC :BookCatalogue
JC :JournalCatalogue
register(it) [Journal]
catalogue(it)
[hardBack]
register(it)
[softBack]
Have different objects for cataloguing books and journal
Journals and softback books are registered
Hardback books are catalogued
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
23
CLASS DIAGRAMS
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
24
Class Diagrams - Operations
Book
Copy
Title : String
of
CopiesOnShelf() : Integer
Borrowed() : Status
Copies(…) : Status
ShelfMark : smT
Borrow():Status
ReMark(m:smT):
An operation –
something that instances of this class can do, which can be
externally invoked
A unit of functionality which is externally exposed
Corresponds to a Java Method
Type for each parameter and the result (“void” if no result)
Direction for each parameter – in, out, inout
UML terminology is message-passing An object’s operation is invoked by another object sending
it a message
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
25
Class - Visibility
Item
Book
- Title : String
+ copiesOnShelf() : Integer
Journal
Visibility
+
public
#
~
-
protected
package
private
accessed by any client of the class –
default for operation
typically from same class or sub-class
typically anything in the same package
typically, from the same class default for attribute
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
26
Class - Interfaces
Interface - same concepts as in Java
A collection of operations
which must be supported by any class claiming to support the
interface (“match” the interface; “realise” the interface)
“supports” is shown as specialisation with dashed arrow
An interface is like a class but has no instances –
no attributes, no associations
Item
Book
Journal
Is part
of
contains
Article
printOffColour()
printOffB&W
…
Pamphlet
printOffColour()
printOffB&W()
…
UML for Use Cases, Jan 5/6 2006
<<interface>>
Copyable
printOffColour()
printOffB&W()
Redundant – don’t need both
Other Aspects of UML
27
Association Classes
Student
takes
0..*
6
Module
IsTaking
Mark : int
To model there being some information and/or operations for
an association between two classes
Could be done using an ordinary class
Student
1
6
takes
0..*
Mark
6
Module
Student
1
0..*
0..*
1
Or 6
Mark : int
Mark : int
Less clear
•
Would have to implement it in one of these ways
Other Aspects of UML
Module
1
0..*
Mark
•
UML for Use Cases, Jan 5/6 2006
6
28
Parameterised Classes
For generic, customisable type definitons
T
List of objects
All of type T
IndexedList
add(t : T, pos: int)
get(pos : int) : T
<<bind>>(Book)
<<bind>>(Citation)
List of
Citations
T – type as parameter
References
BookLIst
List of
Books
Equivalent to References
BookLIst
add(t : Citation, pos: int)
get(pos : int) : Citation
add(t : Book, pos: int)
get(pos : int) : Book
Implementation
language might not
have parameterised
types –
Still may be better to
• Use parameterised
types in the data
structure model
• Use equivalent
explicit types in
implementation
But this duplicates interface definition and understanding - Less clear structure ?
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
29
Constraints
Book
Journal
1
1
{xor}
1..*
Copy
largePrint: bool
braille : bool
aisle : int
shelf : int
1..*
Pre-defined constraint type –
can’t be both a copy of a
book and a copy of journal
{braille implies aisle = 6}
Define constraints within an
element or between
elements
A constraint is a condition that must be satisfied by any correct
implementation.
These are class invariants
Can put constraints on other diagram types
Can be done in natural language or formally in –
Object constraint language (OCL)
Greater precision
Harder to understand
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
30
Object Constraint Language
Manager
Worker must contact
his/her manger via PA,
If there is one
hasPA : Bool
phone:PhoneNo
1
{IF self . lineM . hasPA = True
THEN self . lineMphone =
self . lineM . myPA . Phone
ELSE self . lineMphone =
myPA
Worker
lineM : Manager
lineMphone : PhoneNo
0..1 Administrator
phone : PhoneNo
self . lineM . phone}
Syntax – approximate, see
http://www.omg.org/technology/documents/formal/uml.htm
Chapt 6
Other contexts –
Class Diag. – Operation pre and post conditions
State diag., activity diag., sequence diag. - Guards
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
31
CLASS DIAGRAMS
Goals
To give an appreciation of full power of UML
Content

(increasingly more technical)
New Diagrams / Concepts

Component Deployment

State Diagrams

Collaboration Diagrams

Customisation – stereotypes and properties

Packages
Further Features of previous diagrams

Sequence Diagrams

Class Diagrams
References and Summary
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
32
SUMMARY OF UML
Requirements – Use Case Diag.
Structure –
Class, Object, Deployment, Packaging
Behaviour – Draws out detail
1. Track one example through multiple participants
Show how different participants interact in one case
Sequence Diag –

Walk-through of particular use-case
Collaboration Diag. –

Same role as sequence diagrams, butEmphasises Object
linking structure
2. Tracks one participant through all alternative interactions
Shows how different cases interact for one participant
State(chart) Diag.

States and transitions between them
Activity Diagram –

Flow chart
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
33
End - references
http://www.omg.org/technology/documents/formal/u
ml.htm
UML Pocket Reference, O’Reilly,
ISBN: 0-596-00497-4
UML in a Nutshell
Using UML – Software Engineering with Objects and
Components, Perdita Stevens with Rob Pooley
ISBN: 0-201-64860-1
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
34
Questions?
UML for Use Cases, Jan 5/6 2006
Other Aspects of UML
35
Download