Introduction to the Unified Modeling Language (UML)
Delos NoE , Preservation Cluster
Workshop: Persistency in Digital Libraries
13. February 2006, Oxford Internet Institute
1
„Nobody, not even the creators of UML, understand or use all of it. Most people use a small subset of the UML and work with it.“
„UML is so complex that the standard is often open to multiple interpretations.“
„People do adopt conventions both in the industry widely and within a particular project.“
(Martin Fowler, „UML Destilled“)
Introductory Quotations
2
UML – what is it good for?
• Visualisation: graphical representation of structures and processes
• Specification: Building models that are precise, unambigous and complete
• Construction: Converting UML-models into programming code
• Documentation: Illustration and mapping of systems architecture, requirements analysis, managing different versions of systems or parts of it
3
Basic concepts: What is an object?
An object can be
A thing, e.g., car, office, book
A person, e.g., librarian, director
A term, e.g., programming language, disease
Synonymously, it is also called instance.
4
An object can be featured
by
• State• Behaviour• Identity
5
UML Representation of an object
elisabeth elisabeth:Cow :Cow
object:Class
6
The state of an object includes its attributes and its relationships to other objects.
An attribute can have a value.
:Cow
Colour = brownAge
:Cow
Colour : stringAge : integer = 5
Object:Class
Attribute : type= value
Object: State
7
Objects perhaps „know“ each other, that is there is some kind of relationship between the objects. Depending on the context, a relationship is called link or association or generalisation.
Examples:Cow ‚Elisabeth‘ is the daughter of cow ‚Victoria‘.Cow ‚Elisabeth‘ is suckling from ‚Victoria‘.A calf is a young cow.
8
The behaviour of an object is described through one or more operations. They enable us to modify or request the object's state.
Object: Behaviour
getDigitalObject()
loadData()
9
Every object has a distinct identity that is defined through its existence.
Object: Identity
Identity„Pseudo-Identity“
:Person :Person:Person :Person
:Person :Person :Person
Name=Michael Name=Michael
Name=John Name=John Name=John
Name=Mary Name=Linda
10
The relations between objects can be visualised using an Object Diagram.
An Object Diagram describes objects, links and optionally attributes and their values at a specific point in time. An Object Diagram is a snaphot of a system or parts of it.
Object Diagram
11
Example
Victoria:Cow
Elisabeth:Cow
Charles:Cow
Sex = mAge = 10
12
A class represents a collection of objects. It defines the data structure (attributes), behaviour (operations) and relationships of the single objects.
Every object belongs to exactly one class.
Class
13
UML representation of a class
Class
Class
Class
:DigitalObject
Attribute
Operation
Class
Attribute
Class
Operation
ID=1234DOType : IntegerREFNO=Q34R
ID=1234DOI=123.456
REFNO=Q34R
:DigitalObject
ID=5678DOType : IntegerREFNO=Q56S
DigitalObject
IDDOTypeREFNO
getDigitalObject()
14
Attributes describe the properties of an object (class).
Attributes represent the data structure of an object (class).
All objects of a class share the same attributes. They differ in the values of the particular attributes.
Every attribute has a distinct type.
Attribute
15
UML syntax for attributes
Attribute DigitalObject
ID ID: int ID: int {read only}
ID: int = 1234 ID: int [1] ID / ID
int ID
attribute attribute: type attribute: type {property string}attribute: type = Inital value attribute: type [x..y] class scope attribute /derived attribute type attribute
not normative!
16
Operations are the actions that a class (the objects of a class) can carry out.
All objects of a class use the same operations.
All operations together represent the behaviour of the class (the objects).
Operation
17
UML syntax for operations
Operation
name (parameter-list) : return-type {property-string}
assignID (int: ID) : void {read-only}
18
Objects can be linked to each other. Classes can also be linked. This is called association.
Association
:DigitalObject
DigitalObject Date
:Date:DigitalObject
:Date
association
19
Binary / Reflexive Association
CollectionDigitalObject11..*
DigitalObject
Reflexive A.
Binary A.
20
Multiplicity
Multiplicities enable to model the number of possible links between objects of classes.
CollectionDigitalObject11..*
Multiplicities
21
Examples for multiplicities
exactly one 1
one or none 0..1
uspecified number *
n to many 2..*
n to n 12..49
22
An association can be labeled by using a verb phrase:
CollectionDigitalObject11..*
is part of
23
An association can also be labeled by a property name
(role).
DigitalObject master
1
copy1..3
property names
24
Associations can be completed by constraints.
DigitalObject master
1
copy1..3
constraint
{integrity checked}
25
Aggregation and Composition
Aggregation and Composition are concepts for modelling a „whole-part“ relationship.
Example: „ A page is part of a book.“
They are both special kinds of association. They can also always be expressed as simple associations.
26
Aggregation
UML syntax:
Collection DigitalObject
aggregated class
aggregation
partial class
27
Collection DigitalObject
Collection DigitalObject1..*
1..*
1..* 1..*
is part of
28
Composition
UML syntax:
Collection DigitalObject
aggregated class
composition
partial class
29
Collection DigitalObject
Collection DigitalObject1..*
1 1..*is part of
Page273
Book
title=„UML“
30
Navigability of associations
The navigabilty specifies the access to objects of given classes.
classX classY
classX
classX
classX
classY
classY
classY
unspecified
unidirectional
bidirectional
excluded navigability
31
Properties modelled as attributes or associations
DigitalObject
ID: int [1]created: Date [1..*]
composed: File [1..*]
Digital Object
FileDate
1
1..*
1
1
32
A generalisation describes a relationship between a super class and a sub class.
The sub class is a specialised class in regard of the super class. It is entirely consistent with the super class, but it adds some additional attributes or operations.
Every object of the sub class can be described with an „is a“ relationship.
Generalisation
33
34
Abstract Class
35
A package is used to merge elements of models, especially classes.
They can be grouped in practicable units.
Packages are a good concept for describing the structure of a system on an abstract level.
A complete software system is at its highest level one big package.
Package
36
37
Visibility
Attributes and operations within a class can be labeled by a visibility indicator.
The same is valid for roles in associations.
Most common are „+“, that stands for public and
„-“ that stands for private.
Public elements can be used by any other class, private elements only by the class that owns them.
Additional features
38 Notes
There is a possibility to insert comments into any UML diagram using the following graphical elements:
39
DigitalObject
- ID
- RefNo
- CatType
- checkIntegrity()
+ getDigitalObject()
DigitalObject
AccessUnit
+ copy
*
*
Visibility: Attribute, Operation and property name
40
Dependency
A dependency indicates changes to one element caused by changes of the other.
UML allows the usage of dependencies for all sorts of elements.
AccessUnit DigitalObject
dependency
41
Dependencies can be detailed using a keyword.
AccessUnit DigitalObject<<call>>
42
Often, relationships imply dependencies.
AccessUnit DigitalObject**
Report Document
43
„If someone were to come up to you in a dark alley and say, ‚Psst, wanna see a UML diagram?‘ that diagram would probably be a class diagram.“
(Martin Fowler, „UML Destilled“)
Class diagram
44
The Class Diagram represents a static view of a system.
Therefore Class Diagrams are often used to model structural issues like the architecture of a system or parts of it.
The Class Diagram models single components of the system or parts of it and describes its relationships.
It can be a starting point for transforming the systems model into programming code.
Class Diagram
45
Example 1 – Part of system architecture
Source: http://bdn.borland.com/
46
Example 2 - Conceptual Model: Taxonomy
Source:http://www.agilemodeling.com
47
Example 3 – Producing software
class Person { protected string name; public void generateAddress();} class Foreigner extends Person {}
class Citizen extends Person {}
48
More static views
Package Diagram
Package diagrams are often used to show the static structure of large systems on a high level.
<<call>>
49
So far we regarded the static and structural side of systems.
UML offers some more diagrams for modelling behavioural and dynamic aspects of systems.
Behavioural diagrams show systems in action.
Behavioural and Dynamic Aspects: More UML Diagrams
50
A system in action can be described as one that has at any given time a set of defined states .
States change in a time span. This is called transition.
The UML diagram that describes states of a system or of elements of it (i.e. of particular objects) at a given time (span) is called State Machine Diagram.
State Machine Diagram
Example
51
Core graphical elements
final state
inital statesub-state pointer
transition arrow
event
State box
decision node
Example (2)
52
entry activityexit activity
fork
join
53
A transition can be labelled in three parts (optional):
openkey turned [unblocked] /open door
trigger activity
guard condition
54
Activity State: States with an ongoing activity
Query sentWorking
do/ search for entry
55
Activity Diagrams provide a technique for describing work flows or procedures of a system.
An Activity Diagram shows the system in action in a more general view, not regarding just one particular object, but a sequence of actions where different objects may be involved.
Activity Diagram
56
Initial node
action
exception
objectactivity final
condition
decision
Errorflow
57
A Communication (Collaboration) Diagram is a technique
to show how messages flow between particular objects.
It visualises the interactions between the objects and shows how the objects are linked together.
The Sequence Diagram is an alternative kind of Interaction Diagram besides the Communication Diagram.
Communication Diagram
58
Notation features
link
dataflow arrow
(flat) numbering object
self link
59
Fowler, Martin: UML destilled (3d edition), 2004.
OMG: Unified Modeling Language (UML), Version 2.0 .
Link (01. Feb. 2006): http://www.omg.org/technology/documents/formal/uml.htm
(= Specification of the UML)
Balzert, Heide: Lehrbuch der Objektmodellierung, 2005.
References