UML and WSDL for JISC e-Learning Projects UML – ADDITIONAL FEATURES Richard Hopkins

advertisement
UML and WSDL
for JISC e-Learning Projects
UML – ADDITIONAL FEATURES
Richard Hopkins
rph@nesc.ac.uk
NeSC Training Team Member
Goals and Overview
Goals –
To enable you to appreciate more of UML
To introduce some features that you might
find useful
Overview
Sequence Diagrams & Statecharts
General Features - Extensibility
Class Diagrams
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
2
Conditions in Sequence Diags.
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
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
3
Statecharts
Statecharts –
Self Transitions
Actions
Alternatives
Action on transition –
Action1 / Action2 / …
[ isSpoilt ] / notifyAbuse()
In Bindery
Statechart
For Copy
Class
On Loan
Return()
StatusCheck()
On Shelf
[ not isSpoilt ]
Self-transition
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
Alternatives –
decision diamond
guards
As in activity diag. (flowchart)
4
Statecharts – entry / exit actions
Attribute book:Book
Invoke its isAvail operation
Borrow()
Statechart
For Copy
Class
/ book . isAvail(self)
On Loan
On Shelf
Borrow() / book . notAvail(self)
Rebind()
/ book . notAvail(self)
In Bindery
Borrow()
On Loan
On Shelf
entry
exit
/ book . isAvail(self)
/ book . notAvail(self)
Borrow()
Rebind()
In Bindery
entry / done whenever enter state
exit / done whenever exit state
Clearer and less words
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
5
Sequence Diagrams & Statecharts
Overview
Sequence Diagrams & Statecharts
General Features - Extensibility
Class Diagrams
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
6
Stereotypes
Adding extra classification to model elements
Pre-defined
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
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
7
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
Tagged value – tag is name of property, can be omitted if value
is unique to property
Just as a class has an attribute, and object has value for it
So, element type has property, and instance has property value
UML itself is a UML-expressible model
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
8
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
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
9
Stereotype vs Property
Class Diag.
{layer=UserAgents,
LibraryService language = Java,
AWebService}
Class Diag.
Vs.
{layer=CommonService,
AuthenticationService language = C++,
AWebService}
<<UserAgentLayer>>
<<InJava>>
<<WebService>>
LibraryService
<<ComonServiceLayer>>
<<InC++>>
<<WebService>>
AuthenticationService
How significant is the characteristic?
Very Significant (to user) -> use stereotype
Being a web service Which layer (since lower layers can’t use higher
ones)
Relatively incidental -> use property
Which language used in implementation
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
10
Class Diagrams
Overview
Sequence Diagrams & Statecharts
General Features – Extensibility
Class Diagrams





Specialised Class vs Attribute
Interfaces
Parameterised Classes
Constraints
Association Class
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
11
Specialised Class vs Attribute
Stereotype vs Property
Like difference between specialised class or
attribute of general class
Vs.
Book
Book
hardBack: bool
HardBackBook
SoftBackBook
Use specialised class if a significant difference
to user,
e.g. hardBack has a reBind operation, but
softBack doesn’t
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
12
Interfaces
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
Leaflet
printOffColour()
printOffB&W
…
Is part
of
contains
Article
printOffColour()
printOffB&W
…
<<interface>>
Copyable
printOffColour()
printOffB&W
Redundant – don’t need both
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
13
Interfaces
CopyService
Supports interface
lollipop
Copyable
Copyable
Leaflet
Article
<<interface>>
Copyable
printOffColour()
printOffB&W
(Design)
Dependency
Association
( instances can
knows about)
Lollipop dependency asserts that copyService is only
dependent on the Copyable interface of the associated
objects
Other things can have “Supports interface” lollipop –
use-cases, components
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
14
Parameterised Classes
Alternatively T
T
IndexedList
IndexedList
add(t : T, pos: int)
get(pos : int) : T
add(t : T, pos: int)
get(pos : int) : T
<<bind>>(Citation)
References
<<bind>>(Book)
BookLIst
IndexeddList<Book>
IndexedList<Citation>
The parameterised class is not really a class
A function from classes to a class
Sometimes called a template
Used to avoid duplication, can be easier to read
The parameter (T) is almost always used in the templates
attributes and operations –
It is use of class variable in this way which is the point
Otherwise, could make IndexedList an interface supported
by both
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
15
Parameterised Classes
BIoSystem
<<bind>>(Null)
Null
Cell
(Cell)
(Organism)
Organism
Population
T
(Populaton)
(EcoSystem)
EcoSystem
BioRegion
1..*
BioComponent
X is a particular kind of Biosystem having Y as its constituents
Cell
Organism
Population
EcoSystem
BioRegion
A BioRegion comprises a collection of EcoSystems, comprises a
collection of Populations, comprises ….
Which is a better model ?
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
16
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..*
1
0..*
6
Or -
Mark : int
6
1
0..*
Mark
Mark : int
• Less clear
• Would have to implement it in one of these ways
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
Module
17
Constraints
Book
Journal
1
1
{xor}
1..*
Copy
largePrint: bool
braille : bool
aisle : int
shelf : int
1..*
Pre-defined constrain 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
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
18
Object Constraint Language
Worker must contact
His/her manger via PA,
If there is one
Manager
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 –
Operation: pre and post conditions
State diag., activity diag, sequence diag -Guards
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
19
END - references
http://www.omg.org/technology/documents/formal/uml.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
JISC UML/WSDL – UML, Additional Features, 18th Nov. 2004
20
Download