Sie sind auf Seite 1von 9

This Tutorial is …

Understanding
• about conceptual modeling issues.
Advanced UML Concepts • addressing the domain analysis view point.
• restricted to state modeling (class models).

Gerd Wagner
http://GerdWagner.rezearch.info

Gerd Wagner: Understanding Advanced UML Concepts 2

This Tutorial is not … General Overview


• Part I: Warm Up
• about design or implementation modeling. • Part II: Association Classes
• discussing platform technologies. • Part III: Customizing UML Standard
• discussing behavior modeling (interaction Model Elements
diagrams and activity graphs). • Part IV: Powertypes
• Part V: Aggregation/Composition
• Part VI: Expressing Integrity Constraints
with OCL
Gerd Wagner: Understanding Advanced UML Concepts 3 Gerd Wagner: Understanding Advanced UML Concepts 4

Overview Part I: Warm Up Classifying Objects


• Objects of the same type can be classified by
means of an object class which is visualized as a
• Objects and Classes rectangle labelled with the name of this class.
• Links and Associations P a tie n t

• Role Names
• Generalization 8 3 2 : P a tie n t 1 5 6 1 : P a tie n t

• (Integrity) Constraints
9 4 5 : P a tie n t

7 1 2 : P a t ie n t 8 6 3 : P a t ie n t

Gerd Wagner: Understanding Advanced UML Concepts 5 Gerd Wagner: Understanding Advanced UML Concepts 6

1
The Association has between
Patient and Consultation Associations with Role Names
“An instance of an Association is a Link, which is a tuple of
Instances drawn from the corresponding Classifiers.”

Patient
has
Consultation
W ife

has
Person isMarriedW ith
832 : Patient 19940221032 : Consultation
has
872 : Patient 19990831074 : Consultation
has
Husband
1561 : Patient 20010413055 : Consultation

Gerd Wagner: Understanding Advanced UML Concepts 7 Gerd Wagner: Understanding Advanced UML Concepts 8

Generalization Integrity Constraints


! In order to exclude system states that are not
Employee consistent with the intended information model,
EmpNo various types of integrity constraints can be
Nurse Doctor
Name expressed in a class model.
Address
EmpNo
Name
EmpNo
Name
! Important attribute constraints are:
Address Address ! mandatory (default) versus optional, and
Ward AcademicDegree
! single-valued (default) versus multi-valued.
! Multiplicity constraints define for an association
Nurse Doctor how many objects of one participating class can
Ward AcademicDegree be associated with how many objects of the other
one.
Gerd Wagner: Understanding Advanced UML Concepts 9 Gerd Wagner: Understanding Advanced UML Concepts 10

Integrity Constraints (cont.)


• An association may be
– functional (many-to-one),
– inverse functional (one-to-many),
– total Part II
– inverse total
• Many-to-many associations are neither Association Classes
functional nor inverse functional.
• Uniqueness constraints for defining keys are
not well supported by UML 1.
Gerd Wagner: Understanding Advanced UML Concepts 11

2
Consider the association hasAppointmentWith: Consider the association hasAppointmentWith:
hasAppointmentWith hasAppointmentWith
Patient Doctor Patient Doctor
* * * *

Problem: How to include the date and time of Problem: How to include the date and time of
an appointment? an appointment?

hasAppointmentWith Doctor
Patient Date
* * Time

Is this a solution?
Gerd Wagner: Understanding Advanced UML Concepts 13 Gerd Wagner: Understanding Advanced UML Concepts 14

The Association Class Appointment No!


PatientNo DoctorNo Date Time
Appointment 0832 17 21-Dec-01 15:10
Date
Time 0832 24 19-Dec-01 16:45
* * 0269 24 03-Jan-02 8:30
Patient Doctor 0588 15 20-Dec-01 9:15
0832 17 28-Dec-01 9:30
Question: Can a patient have more than 0699 13 28-Dec-01 9:30
one appointment with the same doctor? … … … …

Gerd Wagner: Understanding Advanced UML Concepts 15 Gerd Wagner: Understanding Advanced UML Concepts 16

Turning an Association Appointments as an Object Class


into an Object Class
DoctorNo Date Time PatientNo
17 21-Dec-01 15:10 0832
1 * Appointment * 1 24 19-Dec-01 16:45 0832
Patient Date Doctor 24 03-Jan-02 8:30 0269
Time
15 20-Dec-01 9:15 0588
17 28-Dec-01 9:30 0832
When we “objectify” an association (class), we can have
more than one link between the same objects. 13 28-Dec-01 9:30 0699
Note that such a class still represents a relationship type, … … … …
and not an entity type!
Gerd Wagner: Understanding Advanced UML Concepts 17 Gerd Wagner: Understanding Advanced UML Concepts 18

3
Association Class
An association class
versus Object Class
• … is an association that is also a class. Appointment
Date
It not only connects a set of classes but Time

also defines a set of features that * *


Patient Doctor
belong to the relationship itself and not
any of the classes. is equivalent with
1 * Appointment * 1
Patient Date Doctor
Time

{unique}

Gerd Wagner: Understanding Advanced UML Concepts 19 Gerd Wagner: Understanding Advanced UML Concepts 20

Questions

Are the following concepts association classes


or object classes?
• a job
Part III
• a book reservation (in a library)
• a purchase (of a product individual) Customizing UML Model Elements
Make a justifiable choice between the two
possibilities, and draw a corresponding class
diagram, including all natural role names.
Gerd Wagner: Understanding Advanced UML Concepts 21

Tags, Constraints and Stereotypes Tag Definitions

• are used in the definition of UML itself • allow to specify user-defined meta-
for defining standard model elements attributes (tagged values) for a model
that are not considered complex enough element
to be defined directly as UML • should be defined in conjunction with a
metaclasses stereotype since that allows them to be
• A coherent set of Tags, Constraints and used in a more disciplined manner
Stereotypes, defined for specific • Example of a predefined tag: derived
purposes, constitutes a UML profile. (refers to ModelElement)
Gerd Wagner: Understanding Advanced UML Concepts 23 Gerd Wagner: Understanding Advanced UML Concepts 24

4
Constraints
Examples of Tag Definitions • allow to specify semantics/usage for a model
element
Tag Base Class Type Multi- • may be expressed by means of (predefined or
or plicity user-defined) keywords, or in a
– designated constraint language (such as OCL)
Stereotype
– a programming language
aliasNames ModelElement UML::Datatypes: * – mathematical notation, or
:String – natural language
• can be enforced by a tool, if it “understands” the
derived ModelElement UML::Datatypes: 1 syntax and semantics of the constraint language.
:Boolean • Example of a predefined constraint keyword:
disjoint (refers to Generalization)
Gerd Wagner: Understanding Advanced UML Concepts 25 Gerd Wagner: Understanding Advanced UML Concepts 26

Stereotypes (1) Stereotypes (2)


• provide a way of branding model • may be used to indicate a difference in
elements meaning or usage
• allow adding user-defined categories of • may be defined as a subclass of one or
UML model elements by referring to a more existing stereotypes inheriting their
base class, which is a class in the UML constraints and tag definitions
metamodel such as Class, Association, • Example of a predefined stereotype:
etc. «type» (refers to Class)
• may specify additional constraints and
tag definitions

Gerd Wagner: Understanding Advanced UML Concepts 27 Gerd Wagner: Understanding Advanced UML Concepts 28

Example: UML Profile for


Business Modeling
Stereotype Base Parent Constraints
Class
Worker Class NA None Part IV
«worker»
Powertypes
CaseWorker Class Worker None
«caseWorker»

Gerd Wagner: Understanding Advanced UML Concepts 29

5
Powertypes Example: ProductType
Supplier
• are special classes, designated with the Enterprise
1 1
ProductIndividual
stereotype !powertype"
*

• In UML 1: “a user-defined metaelement 1

Customer
whose instances are classes in the Organization

1
«powertype»
model.” ProductType
{disjoint, complete}
LegalEntity
• In UML 2: “a class whose instances are
subclasses of another class”. Person

Gerd Wagner: Understanding Advanced UML Concepts 31 Gerd Wagner: Understanding Advanced UML Concepts 32

Subclass Partitions and


Nested Powertype Constructions
Powertypes
PolicyLine • The instances of a powertype of order 1
PolicyCoveragType Policy InsuranceLine
1 * * 1
are subclasses of a base type (not a
powertype).
Examples: EngineType, CarType
:PolicyCoverageType :InsuranceLine
• The instances of a powertype of order 2
GroupPolicy LifePolicy
are powertypes of order 1.
IndividualPolicy HealthPolicy
Example: ProductType
• The instances of a powertype of order n
PropertyPolicy
are powertypes of order n-1.
Gerd Wagner: Understanding Advanced UML Concepts 33 Gerd Wagner: Understanding Advanced UML Concepts 34

Questions

• Make a diagram for AccountType,


Account, CheckingAccount,
SavingsAccount. Part V
• Find another example of a powertype.
Aggregation and Composition

Gerd Wagner: Understanding Advanced UML Concepts 35

6
Aggregation Composition

• An aggregation is a part-whole • If the parts in the part-whole relationship


relationship, that is, a special binary are non-shareable, it is called a
association where the instances on one composition (visualized as a black
side are aggregates (or wholes) and the diamond).
instances on the other side are their • “A shareable aggregation denotes weak
parts. ownership; that is, the part may be
• An aggregation relationship may be included in several aggregates and its
called isPartOf or consistsOf. owner may also change over time.”
Gerd Wagner: Understanding Advanced UML Concepts 37 Gerd Wagner: Understanding Advanced UML Concepts 38

Ex: An organization is composed Mandatory Aggregates and


of teams that consist of persons. Mandatory Parts
1 0..1
Engine Car

Organization Team Person


1 * * 2..* Engine is a mandatory part of Car, and Car is
an optional aggregate for Engine.
Notice that Organization is a mandatory aggregate for
1 1
Team, whereas Team is an optional aggregate for Person.
Heart HumanBody

Heart is a mandatory part of HumanBody,


and HumanBody is a mandatory aggregate
for Heart.
Gerd Wagner: Understanding Advanced UML Concepts 39 Gerd Wagner: Understanding Advanced UML Concepts 40

Lieftime Dependency Inseparable and Essential Parts

• UML 1: “the composite object is


responsible for the creation and 1
{essential = true,
destruction of its parts” “if the composite inseparable = true} 1

is destroyed, it must destroy all its parts” Brain Person

• However: lifetime dependency is a


characteristic of part-whole relationships Brain is an inseparable and essential part of Person.
with inseparable parts.
• We can define our own tags for
expressing this.
Gerd Wagner: Understanding Advanced UML Concepts 41 Gerd Wagner: Understanding Advanced UML Concepts 42

7
Inseparable Parts may be Shareable An aggregation relationship is
Lecture RegularCourse
1..* 1 • anti-symmetric: when an object o1 is
{inseparable = true}
*
part of an aggregate object o2, then o2
StudiumGeneraleCourse cannot be part of o1
*
• transitive: when an object o1 is part of
Although Lecture is an inseparable part of RegularCourse,
an aggregate object o2, and o2 is part
it is shareable.
of another aggregate object o3, then o1
is also part of o3.

Gerd Wagner: Understanding Advanced UML Concepts 43 Gerd Wagner: Understanding Advanced UML Concepts 44

Expressing Constraints with the


Object Constraint Language (OCL)
• There are many types of constraints that
cannot be expressed visually but have to be
Part VI included as a piece of text, or a symbolic
expression, in a class diagram.
• OCL can be used to write unambiguous
Expressing Integrity Constraints constraints that can't be misinterpreted.
with OCL • OCL expressions do not have any side
effects, which means that evaluating an OCL
expression will not affect the object to which
the expression is applied.
Gerd Wagner: Understanding Advanced UML Concepts 46

OCL (continued) Business Rules

• All expressions in OCL have a type and • A rental car is available, if it is not
evaluate to a value from that type when assigned to a rental contract, and it
applied to a specific context. does not require service.
• In OCL, a constraint is called an • A driver of a rental car must be at least
invariant. 25 years old.
• In addition to invariants, OCL allows to • The age of a person is computed as the
define preconditions and postconditions difference between the current year and
for operations. the person’s birth year.
Gerd Wagner: Understanding Advanced UML Concepts 47 Gerd Wagner: Understanding Advanced UML Concepts 48

8
Expressing Business Rules with
Bibliography
OCL Invariants
0..1 /isDrivenBy 0..1
• James Martin and James Odell. Object-
Oriented Methods: A Foundation (UML
RentalCar
isAssignedTo Driver Person Edition), Prentice-Hall, 1998. This book
RentalCarID : String
requiresService : Boolean
RentalContract Name : String
DateOfBirth : Date
presents the fundamental concepts
1 0..1 * 1
/isAvailable : Boolean /Age : Integer underlying the object-oriented approach in a
clear, concise manner using the Unified
«invariant»
Modeling Language (UML). It also introduces
«invariant»
{ RentalContract->isEmpty
and not requiresService
{Driver.Age>24}
«invariant»
{Age = Year() - Year(DateOfBirth)}
more advanced structures—including
implies isAvailable} constraints, business rules, meta-modeling,
power types, and dynamic and multiple
classification.
Gerd Wagner: Understanding Advanced UML Concepts 49 Gerd Wagner: Understanding Advanced UML Concepts 50

Das könnte Ihnen auch gefallen