Vous êtes sur la page 1sur 35

UML Tutorial

Heinrich Hussmann
Technische Universität Dresden

Gianna Reggio
Università di Genova

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Semi-Formal Development Methods
1960 1970 1980 1990 2000 2010

Combinations Object-oriented
Modelling
Function Modelling

Data Modelling

State Modelling

Event Modelling

ERM Statecharts
SA/SD SREM SSADM OMT UML
Heinrich Hussmann Technische Universität Dresden UML Tutorial
Roots of UML
OOD
Booch

OOSE OMT
Jacobson Rumbaugh et al.

1995:
Booch / Rumbaugh / Jacobson
1997: UML 1.1 (OMG adopted technology)

• UML is a scond generation notation for diagram-based


object-oriented modelling
• UML was a development of the company Rational Corp. (Booch)
• UML is now further developed as an industry standard by the
Object Management Group (OMG)
Heinrich Hussmann Technische Universität Dresden UML Tutorial
Impact of UML
• The following companies were involved among others in the OMG
proposal for UML:
– Rational
– Microsoft
– Hewlett-Packard
– Oracle
– IBM
– Unisys
– Platinum
– Softeam
– ...
• Well-known methods are reshaped in a UML-conformant way:
– Fusion (Coleman et al.)
– Catalysis (D'Souza et al.)
– OOSA (Odell/Martin)

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Scope of UML
• UML is a notation, not a method !
– UML can be applied in all phases of the development process
– "Rational Unified Process" - a process for UML
• UML covers all levels of formality
– informal requirements analysis (use cases)
– semi-formal o-o modelling (static and dynamic models)
– purely formal modelling and specification (OCL)
• UML is extensible
– Generic constructs:
» stereotypes (e.g. <<uses>>, <<derived>>)
» element properties (e.g. {abstract}, {author="John"})
» constraints (e.g. {disjoint}, {subset})
– Example for an UML extension:
» Real-time UML
» based on ROOM (Selic et al.)

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Information on UML
• UML Resource Center: http://www.rational.com/uml
– UML Notation Guide
– UML Semantics
– Object Constraint Language Specification
• OMG UML Revision Task Force http://uml.shl.com/
• Information on OCL http://www.software.ibm.com/ad/ocl

• Books:
– Booch/Rumbaugh/Jacobson: Unified Modeling Langauge User Guide.
Addison-Wesley 1998. (just published)
– Rumbaugh/Booch/Jacobson: Unified Modeling Language Reference
Guide. Addison-Wesley 1998. (to appear)
– Fowler/Scott: UML Distilled. Addison-Wesley 1997.
– Warmer/Kleppe: The Object Constraint Language - Precise Modeling
with UML, Addison-Wesley 1998 (October !)

Heinrich Hussmann Technische Universität Dresden UML Tutorial


OMG Revision Schedule for UML
• UML 1.2:
– Editorial (non-technical) cleanup revision
– Completed: July 1998
– RFC Comment Deadline: October 1, 1998
• UML 1.3:
– Technical cleanup revision
– Projected completion: November 1998
• UML 1.4:
– Minor revision
– Projected completion: April 1, 1999

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Diagram Types in UML
• Static Structure Diagrams
– Class Diagram
– Object Diagram
• Use Case Diagram
• Interaction Diagrams
– Sequence Diagram
– Collaboration Diagram
• Statechart Diagram
• Activity Diagram
• Implementation Diagrams
– Component Diagram
– Deployment Diagram

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Static Structure Diagram: Class Diagram
Party
name
address Reservation
dateBooked
printLetter() status
cancel()
Course
Company Customer title
0..* 0..* date
turnover custNum
participant totalParticipants
printLetter() printLetter() maxParticipants
1 addReservation()
cancel()
CorpCustomer
0..*
employeeNum
employs department
printLetter()
Heinrich Hussmann Technische Universität Dresden UML Tutorial
Static Structure Diagram: Object Diagram

CorpCustomer

<<instance of>>

x: CorpCustomer
c: Company
employs name = "Joe Smith"
name = "XXY Ltd." adress = ""
adress = "Dresden, ..." custNum = 9876
turnover = 105.23 employeeNum = 1234
department = "A1"

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Use Case Diagram
Course Management

introduce
new course

cancel
course

assign
speakers
programme
maintenance
produce
catalog
customer
service make
reservation

cancel
reservation

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Interaction Diagram: Sequence Diagram

:programme x1: Customer x2: Customer


maintenance
c: course
addReservation()

r1: Reservation
addReservation()

r2: Reservation
cancel()
cancel()
printLetter()

cancel()
printLetter()

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Interaction Diagram:
Collaboration Diagram

3.1.1: printLetter()
r1: Reservation
{new}
x1: Customer
3.1: cancel() 1.1: create()
1: addReservation()

c: course
{new}

2: addReservation()
3: cancel()
x2: Customer 2.1: create
3.2: cancel()
r2: Reservation 0:
3.2.1: printLetter() {new} create()
:programme
maintenance
Heinrich Hussmann Technische Universität Dresden UML Tutorial
Statechart Diagram
Class "Course" update

/ enter data delete


planned

release

course cancelled new reservation


bookable res. cancelled

res. cancelled [is full]


cancelled [timeout]
full
course
do/ cancel cancelled
[timeout]
/ archive data
over

is_full: totalParticipants = maxParticipants


timeout: today >= date
Heinrich Hussmann Technische Universität Dresden UML Tutorial
Activity Diagram

process
reservation

check
reservation

check check
participant availability

reject reject
[ok] [ok]

create
reservation

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Implementation Diagram:
Component Diagram

User Interface

Course
Manager

SQL

Database

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Imlementation Diagram:
Deployment Diagram

Client

User Interface

Server

Client Course
Application Manager

SQL

Database

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Outline
1. History of UML
2. Overview of notations in UML
3. Class Diagrams
4. Statechart Diagrams
5. Sequence Diagrams
6. Object Constraints: OCL

Heinrich Hussmann Technische Universität Dresden UML Tutorial


CL OCL and UML
• OCL = Object Constraint Language
– OCL is officially part of UML 1.1
– History:
» Syntropy (Cook/Daniels 1994)
» IBEL (Integrated Business Engineering Language), IBM
» OCL Definition: Jos Warmer (IBM), submitted by IBM/ObjecTime
– Formal definition of
• invariants
• pre- and postconditions
• guards
• navigation
• OCL is used to define the "context conditions" for UML 1.1 notation
• Practicioners mostly ignore OCL !
– too complex ?
– unnecessary ?
Heinrich Hussmann Technische Universität Dresden UML Tutorial
OCL and Formal Methods

"In order to write un-ambiguous constraints, so-called


formal languages have been developed. The
disadvantage of formal languages is that they are
useable only to persons with a strong mathematical
background, but difficult for the average business or
system modeler to use.
OCL has been developed to fill this gap."

OCL 1.1 Specification, September 1997

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Basic OCL Concepts (1)
• Invariant:
<class name>
<boolean expression>
• Pre/postcondition;:
<class name>::<operation name>(<parameters>)
pre: <boolean expression>
post: <boolean expression>
• self:
– refers to an individual object of the described class
– can be omitted where unambiguous
• Properties:
– Attribute: <object expression>.<attribute>
– Association: <object expression>.<role>
<object expression>.<class name as role>

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Basic OCL Concepts (2)
• Collection types (predefined):
– Set
– Bag
– Seq
• Navigation through association
– results in a Set(Object)
– or in a Seq(Object) if association is marked as {ordered}
• Applying properties on collections:
<collection expression> –> <collection property>
• Predefined properties for collections:
– size, includes, including, select, collect, forall, exists, ...

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Examples of Constraints (1)
Reservation
dateBooked
status
cancel()
Course
Customer title
0..* 0..* date
custNum
participant totalParticipants
printLetter() maxParticipants
addReservation()
cancel()

Course
self.totalParticipants <= self.maxParticipants
Reservation
self.course.date >= self.dateBooked

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Examples of Constraints (2)

Course
Customer title
0..* 0..* date
custNum
dateRegistered participant totalParticipants
maxParticipants
printLetter() addReservation()
cancel()

Course
self.totalParticipants = self.participant->size
Customer
self.course->forall(date >= self.dateRegistered)

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Example of Pre/Postconditions

Course
Customer title
0..* 0..* date
custNum
dateRegistered participant totalParticipants
maxParticipants
printLetter() addReservation()
cancel()

Course::addReservation(c: Customer)
pre: not (self.participant->includes(c))
and (self.totalParticipants < self.maxParticipants)
post: (self.participant = self.participant@pre->including(c))
and
(self.totalParticipants = self.totalParticipants@pre +1)

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Problems with OCL
• Basic problem:
– Definition of OCL is very brief and informal.
– Some semantic issues are not yet tackled properly.

• Examples (partially based on [Gogolla, Richters 98]):


– Meta cycle in type hierarchy (OclType.oclType)
– Incomplete type conformance rules (subtypes of OclAny)
– Incomplete treatment of undefined values *
– Ambiguities in navigation expressions *
– Conversion from Bag or Set to Sequence causes inconsistencies *
– Automatic flattening of collections (simple but may be too weak

* : More information follows.

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Rules for Undefined Values
• OCL Rules:
– Whenever a subexpression is undefined, the complete expression is
undefined.
– Exceptions:
» True OR-ed with anything is True
» False AND-ed with anything is False
– These rules are valid irrespective of the order of the arguments.

• Questions (from [Gogolla, Richters 98]):


– Should not "undefined = undefined" yield True ?
– Should not "if true the 1 else undefined endif" yield 1 ?
– How is undefined related to the quantifiers ?

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Conversion of Collections
Course
self.participant->asSequence

• OCL definition of 'asSequence':


"A sequence that contains all the elements from the set, in random
order."

Set { 1, 2, 3 } -> asSequence yields e.g. Sequence { 1, 2, 3 }


Set { 3, 2, 1 } -> asSequence yields ??

• Assumption of order on types ?


Which order for class types like Customer ?

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Navigation Ambiguities

prequisite
Dependency
Course
examGrade
title
date
totalParticipants
maxParticipants follow-up
addReservation()
cancel()

Course
self.dependency

• OCL does not contain a way to specify the role to be used for this
navigation.

Heinrich Hussmann Technische Universität Dresden UML Tutorial


Tools for OCL

• IBM OCL Parser, Version 0.3


– written in Java (JavaCC), public domain incl. sources
– syntactical checking and partial (!) type checking

Heinrich Hussmann Technische Universität Dresden UML Tutorial

Vous aimerez peut-être aussi