Lecture 6: Class Diagrams I 2016-11-15 Prof. Dr. Andreas Podelski, - - PowerPoint PPT Presentation

lecture 6 class diagrams i
SMART_READER_LITE
LIVE PREVIEW

Lecture 6: Class Diagrams I 2016-11-15 Prof. Dr. Andreas Podelski, - - PowerPoint PPT Presentation

Software Design, Modelling and Analysis in UML Lecture 6: Class Diagrams I 2016-11-15 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universitt Freiburg, Germany 6 2016-11-15 main Course Map N UML W E CD ,


slide-1
SLIDE 1

– 6 – 2016-11-15 – main –

Software Design, Modelling and Analysis in UML

Lecture 6: Class Diagrams I

2016-11-15

  • Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universität Freiburg, Germany

slide-2
SLIDE 2

Course Map

– 6 – 2016-11-15 – main –

2/31

UML

Model Instances

N S W E

CD, SM S = (T, C, V, atr ), SM M = (ΣD

S , AS , →SM )

ϕ ∈ OCL expr CD, SD S , SD B = (QSD, q0, AS , →SD, FSD) π = (σ0, ε0)

(cons0,Snd0)

− − − − − − − − →

u0

(σ1, ε1)· · · wπ = ((σi, consi, Sndi))i∈N G = (N, E, f)

Mathematics

OD

UML !

✔ ✔ ✔ ✔ ✔ ✔

slide-3
SLIDE 3

Content

– 6 – 2016-11-15 – Scontent –

3/31

  • Stocktaking
  • Extended Signatures
  • Structures for Extended Signatures
  • Semantically Relevant
  • Mapping Class Diagrams to

Extended Signatures

  • What if things are missing?
  • (Temporary) Abbreviations
  • Stereotypes
slide-4
SLIDE 4

UML Class Diagrams: Stocktaking

– 6 – 2016-11-15 – main –

4/31

slide-5
SLIDE 5

Recall: Signature vs. Class Diagram

– 6 – 2016-11-15 – Sstock –

5/31

Basic Object System Signature Another Example

– 2 – 2016-10-20 – Ssemdom –

7/20 S = (T, C, V, atr ) where

  • (basic) types T and classes C (both finite),
  • typed attributes V , from T , or C0,1 or C, for some C C ,
  • atr : C 2V mapping classes to attributes.

Example:

slide-6
SLIDE 6

That’d Be Too Simple

– 6 – 2016-11-15 – Sstock –

6/31

  • Stereotype1, . . . , Stereotypen
  • Package::C

+ r : Package::C0,1 = expr s : D∗ {ordered} − v : Int = 27 w : Float {readOnly}

A

y : Int

B

{A}

D

x : Int

slide-7
SLIDE 7

What Do We Want / Have to Cover?

– 6 – 2016-11-15 – Sstock –

7/31

A class

  • Stereotype1, . . . , Stereotypen
  • Package::C

+ r : Package::C0,1 = expr s : D∗ {ordered} − v : Int = 27 w : Float {readOnly}

A

y : Int

B

{A}

D

x : Int

  • has a set of stereotypes,
  • has a name,
  • belongs to a package,
  • can be abstract,
  • can be active,
  • has a set of attributes,
  • has a set of operations.

Each attribute has

  • a visibility,
  • a name, a type,
  • a multiplicity, an order,
  • an initial value, and
  • a set of properties, such as readOnly, ordered, etc.

Wanted: places in the signature to represent the information from the picture.

slide-8
SLIDE 8

Extended Signature

– 6 – 2016-11-15 – main –

8/31

slide-9
SLIDE 9

Extended Signature

– 6 – 2016-11-15 – Sextsig –

9/31

  • Definition. An (Extended) Object System Signature is a quadruple

S = (T, C, V, atr ) where

  • T is a set of (basic) types,
  • C is a finite set of classes C, SC, a, t where
  • SC is a finite (possibly empty) set of stereotypes,
  • a ∈ B is a boolean flag indicating whether C is abstract,
  • t ∈ B is a boolean flag indicating whether C is active,
  • V is a finite set of attributes v : T, ξ, expr 0, Pv where
  • T is a type from T , or C0,1, C∗ for some C ∈ C ,
  • ξ ∈ {public

:=+

, private

:=−

, protected

  • :=#

, package

  • :=∼

} is the visibility,

  • an initial value expression expr0 given as a word from a language for initial value

expressions, e.g. OCL, or C++ in the Rhapsody tool; write ‘⊲ ⊳’ to explicitly not give an initial value expression.

  • a finite (possibly empty) set of properties Pv.
  • atr : C → 2V maps each class to its set of attributes.

We use SC to denote the set

C∈C SC of stereotypes in S .

slide-10
SLIDE 10

Extended Signature Example

– 6 – 2016-11-15 – Sextsig –

10/31

S = (T, C, V, atr ), C, SC, a, t ∈ C , v : T, ξ, expr 0, Pv ∈ V S =

  • {Int, Float},

{Package::C, {Stereotype1, . . . , Stereotypen}, 0, 0, A, ∅, 1, 0, B, ∅, 1, 0, D, ∅, 0, 1}, {r : Package::C0,1, +, expr, ∅, s : D∗, +, ⊲ ⊳, {ordered}, v : Int, −, 27, ∅, w : Float, +, ⊲ ⊳, {readOnly}, x : Int, +, ⊲ ⊳, ∅, y : Int, +, ⊲ ⊳, ∅}, {Package::C → {r, s, v, w}, A → {y}, B → ∅, D → {x}}

slide-11
SLIDE 11

Conventions

– 6 – 2016-11-15 – Sextsig –

11/31

  • We write C, SC, a, t if we want to refer to all aspects of class C.
  • If the new aspects are irrelevant (for a given context),

we simply write C i.e. old definitions (written in terms of C) are still valid.

  • Similarly, we write v : T, ξ, expr 0, Pv if we want to refer to all aspects of attribute v.
  • Write only v : T or v if details are irrelevant.
slide-12
SLIDE 12

Structures of Extended Signatures

– 6 – 2016-11-15 – Sextsig –

12/31

Recall:

  • Definition. A Basic Object System Structure of a Basic Object System Signature

S = (T, C, V, atr ) is a domain function D which assigns to each type a domain, i.e.

  • τ ∈ T is mapped to D(τ),
  • C ∈ C is mapped to an infinite set D(C) of (object) identities.

Note: Object identities only have the “=" operation.

  • Sets of object identities for different classes are disjoint, i.e.

∀ C, D ∈ C : C = D → D(C) ∩ D(D) = ∅.

  • C∗ and C0,1 for C ∈ C are mapped to 2D(C).

We use D(C ) to denote

C∈C D(C); analogously D(C∗).

slide-13
SLIDE 13

Structures of Extended Signatures

– 6 – 2016-11-15 – Sextsig –

12/31

New:

  • Definition. An (Object System) Structure of an (Extended Object System) Sig-

nature S = (T, C, V, atr ) is a domain function D which assigns to each type a domain, i.e.

  • τ ∈ T is mapped to D(τ),
  • C ∈ C is mapped to an infinite set D(C) of (object) identities.

Note: Object identities only have the “=" operation.

  • Sets of object identities for different classes are disjoint, i.e.

∀ C, D ∈ C : C = D → D(C) ∩ D(D) = ∅.

  • C∗ and C0,1 for C ∈ C are mapped to 2D(C).

We use D(C ) to denote

C∈C D(C); analogously D(C∗).

slide-14
SLIDE 14

System States of Extended Signatures

– 6 – 2016-11-15 – Sextsig –

13/31

Recall:

  • Definition. Let D be a basic structure of basic signature S = (T, C, V, atr ).

A system state of S wrt. D is a type-consistent mapping σ : D(C ) (V (D(T ) ∪ D(C∗))). That is, for each u ∈ D(C), C ∈ C , if u ∈ dom(σ)

  • dom(σ(u)) = atr(C)
  • σ(u)(v) ∈ D(τ) if v : τ, τ ∈ T
  • σ(u)(v) ∈ D(D∗) if v : D0,1 or v : D∗ with D ∈ C

We call u ∈ D(C ) alive in σ if and only if u ∈ dom(σ). We use ΣD

S to denote the set of all system states of S wrt.D.

slide-15
SLIDE 15

System States of Extended Signatures

– 6 – 2016-11-15 – Sextsig –

13/31

New:

  • Definition. Let D be a structure of extended signature S = (T, C, V, atr ).

A system state of S wrt. D is a type-consistent mapping σ : D(C ) (V (D(T ) ∪ D(C∗))). That is, for each u ∈ D(C), C ∈ C , if u ∈ dom(σ)

  • dom(σ(u)) = atr(C)
  • σ(u)(v) ∈ D(τ) if v : τ, τ ∈ T
  • σ(u)(v) ∈ D(D∗) if v : D0,1 or v : D∗ with D ∈ C
  • ∀ C, SC, 1, t ∈ C • dom(σ) ∩ D(C) = ∅.

We call u ∈ D(C ) alive in σ if and only if u ∈ dom(σ). We use ΣD

S to denote the set of all system states of S wrt.D.

slide-16
SLIDE 16

Semantical Relevance

– 6 – 2016-11-15 – Sextsig –

14/31

  • The semantics (or meaning) of an extended object system signature S
  • wrt. a structure D is the set of system states ΣD

S .

  • The semantics (or meaning) of an extended object system signature S

is the set of sets of system states wrt. some structure of S , i.e. the set {ΣD

S | D is structure of S }.

Which of the following aspects is semantically relevant, i.e. does contribute to the constitution of system states? A class

  • has a set of stereotypes,
  • has a name,
  • belongs to a package,
  • can be abstract,
  • can be active,
  • has a set of attributes,
  • has a set of operations (later).

Each attribute has

  • a visibility,
  • a name, a type,
  • a multiplicity, an order,
  • an initial value, and
  • a set of properties,

such as readOnly, ordered, etc.

slide-17
SLIDE 17

Mapping UML Class Diagrams to Extended Signatures

– 6 – 2016-11-15 – main –

15/31

slide-18
SLIDE 18

From Class Boxes to Extended Signatures

– 6 – 2016-11-15 – Scdmap –

16/31

A class box n induces an (extended) signature class as follows: n:

  • S1, . . . , Sk
  • C

ξ1 v1 : T1 = expr 1

0 {P1,1, . . . , P1,m1}

. . . ξℓ vℓ : Tℓ = expr ℓ

0 {Pℓ,1, . . . , Pℓ,mℓ}

  • C(n) := C, {S1, . . . , Sk}, a(n), t(n)

V (n) := {v1 : T1, ξ1, expr 1

0, {P1,1, . . . , P1,m1}, . . . , vℓ : Tℓ, ξℓ, expr ℓ 0, {Pℓ,1, . . . , Pℓ,mℓ}}

atr(n) := {C → {v1, . . . , vℓ}} where

  • “abstract” is determined by the font:

a(n) =

  • true

, if n = C

  • r n =

C {A} false , otherwise

  • “active” is determined by the frame:

t(n) =

  • true

, if n = C

  • r n =

C false , otherwise

slide-19
SLIDE 19

Example

– 6 – 2016-11-15 – Scdmap –

17/31

  • S1, . . . , Sk
  • C

ξ1 v1 : T1 = expr 1

0 {P1,1, . . . , P1,m1}

. . . ξℓ vℓ : Tℓ = expr ℓ

0 {Pℓ,1, . . . , Pℓ,mℓ}

  • C(n) := C, {S1, . . . , Sk}, a(n), t(n)

V (n) := {v1 : T1, ξ1, expr 1

0, {P1,1, . . . , P1,m1}, . . . ,

vℓ : Tℓ, ξℓ, expr ℓ

0, {Pℓ,1, . . . , Pℓ,mℓ}}

atr(n) := {C → {v1, . . . , vℓ}}

  • Stereotype1, . . . , Stereotypen
  • Package::C

+ r : Package::C0,1 = expr s : D∗ {ordered} − v : Int = 27 w : Float {readOnly}

A

y : Int

B

{A}

D

x : Int

slide-20
SLIDE 20

What If Things Are Missing?

– 6 – 2016-11-15 – Scdmap –

18/31

It depends.

  • What does the standard say? (OMG, 2011a, 121)

“Presentation Options. The type, visibility, default, multiplicity, property string may be suppressed from being displayed, even if there are values in the model.”

  • Visibility: There is no “no visibility” — an attribute has a visibility in the (extended) signature.

Some (and we) assume public as default, but conventions may vary.

  • Initial value: some assume it given by domain (such as “leftmost value”, but what is

“leftmost” of Z?). Some (and we) understand non-deterministic initialisation if not given.

  • Properties: probably safe to assume ∅ if not given at all.
slide-21
SLIDE 21

Example Cont’d

– 6 – 2016-11-15 – Scdmap –

19/31

  • S1, . . . , Sk
  • C

ξ1 v1 : T1 = expr 1

0 {P1,1, . . . , P1,m1}

. . . ξℓ vℓ : Tℓ = expr ℓ

0 {Pℓ,1, . . . , Pℓ,mℓ}

  • C(n) := C, {S1, . . . , Sk}, a(n), t(n)

V (n) := {v1 : T1, ξ1, expr 1

0, {P1,1, . . . , P1,m1}, . . . ,

vℓ : Tℓ, ξℓ, expr ℓ

0, {Pℓ,1, . . . , Pℓ,mℓ}}

atr(n) := {C → {v1, . . . , vℓ}}

  • Stereotype1, . . . , Stereotypen
  • Package::C

+ r : Package::C0,1 = expr s : D∗ {ordered} − v : Int = 27 w : Float {readOnly}

A

y : Int

B

{A}

D

x : Int

S = {Int, Float}, {Package::C, {Stereotype1, . . . , Stereotypen}, 0, 0, A, ∅, 1, 0, B, ∅, 1, 0, D, ∅, 0, 1}, {r : Package::C0,1, +, expr, ∅, s : D∗, +, ⊲ ⊳, {ordered}, v : Int, −, 27, ∅, w : Float, +, ⊲ ⊳, {readOnly}, x : Int, +, ⊲ ⊳, ∅, y : Int, +, ⊲ ⊳, ∅}, {Package::C → {r, s, v, w}, A → {y}, B → ∅, D → {x}}

slide-22
SLIDE 22

From Class Diagrams to Extended Signatures

– 6 – 2016-11-15 – Scdmap –

20/31

  • We view a class diagram CD as a graph with nodes {n1, . . . , nN}

(each “class rectangle” is a node).

  • C (CD) := {C(ni) | 1 ≤ i ≤ N}
  • V (CD) := N

i=1 V (ni)

  • atr(CD) := N

i=1 atr(ni)

  • In a UML model, we can have finitely many class diagrams,

C D = {CD1, . . . , CDk}, which induce the following signature: S (C D) =

  • T ,

k

  • i=1

C (CDi),

k

  • i=1

V (CDi),

k

  • i=1

atr(CDi)

  • .

(Assuming T given. In “reality” (i.e. in full UML), we can introduce types in class diagrams, the class diagram then contributes to T . Example: enumeration types.)

slide-23
SLIDE 23

Is the Mapping a Function?

– 6 – 2016-11-15 – Scdmap –

21/31

Question: Is S (C D) well-defined? There are two possible sources for problems: (1) A class C may appear in multiple class diagrams: (i)

C

v : Int = 0 CD1

C

w : Int = 27 CD2 (ii)

C

v : Int = 0 CD1

C

v : Int = 27 CD2 Simply forbid the case (ii) — easy syntactical check on diagram.

slide-24
SLIDE 24

Is the Mapping a Function?

– 6 – 2016-11-15 – Scdmap –

22/31

(2) An attribute v may appear in multiple classes with different type:

C

v : Bool

D

v : Int Two approaches:

  • Require unique attribute names.

This requirement can easily be established (implicitly, behind the scenes) by viewing v as an abbreviation for C::v

  • r

D::v depending on the context. (C::v : Bool and D::v : Int are then unique.)

  • Subtle, formalist’s approach: observe that

v : Bool, . . . and v : Int, . . . are different things in V .

slide-25
SLIDE 25

Abbreviations

– 6 – 2016-11-15 – Scdmap –

23/31

Since we have not yet discussed associations, for now we read

  • C

D

  • ×

r

0, 1

as

C

r : D0,1

D

  • C

D

  • ×

r

as

C

r : D∗

D

and

  • C

D

r

0, 1

as

C D

  • ×

r

0, 1

  • C

D

r

as

C D

  • ×

r

slide-26
SLIDE 26

Course Map

– 6 – 2016-11-15 – main –

24/31

UML

Model Instances

N S W E

CD, SM S = (T, C, V, atr ), SM M = (ΣD

S , AS , →SM )

ϕ ∈ OCL expr CD, SD S , SD B = (QSD, q0, AS , →SD, FSD) π = (σ0, ε0)

(cons0,Snd0)

− − − − − − − − →

u0

(σ1, ε1)· · · wπ = ((σi, consi, Sndi))i∈N G = (N, E, f)

Mathematics

OD

UML ✔

✔ ✔ ✔ ✔ ✔ ✔

slide-27
SLIDE 27

Stereotypes

– 6 – 2016-11-15 – main –

25/31

slide-28
SLIDE 28

Stereotypes as Labels or Tags

– 6 – 2016-11-15 – Sstereo –

26/31

  • What are Stereotypes?
  • Not represented in system states.
  • Not contributing to typing rules / well-formedness.
  • Oestereich (2006):

View stereotypes as (additional) “labelling” (“tags”) or as “grouping”.

  • Useful for documentation and model-driven development, e.g. code-generation:
  • Documentation: e.g. layers of an architecture.

Sometimes, packages (cf. OMG (2011a,b)) are sufficient and “right”.

  • Model Driven Architecture (MDA): later.
slide-29
SLIDE 29

Example: Stereotypes for Documentation

– 6 – 2016-11-15 – Sstereo –

27/31

Core View Application/Qt

Trace

sort move filter jump zoom

View/Qt

  • Example: Timing Diagram Viewer

Schumann et al. (2008)

  • Architecture has four layers:
  • core, data layer
  • abstract view layer
  • toolkit-specific view layer/widget
  • application using widget

Stereotype “=” layer “=” colour.

slide-30
SLIDE 30

Other Examples

– 6 – 2016-11-15 – Sstereo –

28/31

  • Use stereotypes ‘Team1’, ‘Team2’, ‘Team3’ and assign stereotype Teami to class C if Teami is responsible

for class C.

  • Use stereotypes to label classes with licensing information (e.g., LGPL vs. proprietary).
  • Use stereotypes ‘ServerA’, ‘ServerB’ to indicate where objects should be stored.
  • Use stereotypes to label classes with states in the development process like “under development”,

“submitted for testing”, “accepted”.

  • etc. etc.

Necessary: a common idea of what each stereotype stands for.

(To be defined / agreed on by the team, not the job of the UML consortium.)

slide-31
SLIDE 31

Tell Them What You’ve Told Them. . .

– 6 – 2016-11-15 – Sttwytt –

29/31

  • Extended Signatures allow us to represent aspects like
  • abstract, active, visibility, initial value expression, ...
  • Not all of these aspects are semantically relevant.
  • The only change on system states

is that abstract classes cannot have instances.

  • Class Diagrams map to Extended Signatures,

i.e. the meaning of a class diagram is the extended signature which it uniquely denotes.

  • Thus a Class Diagram (transitively) denotes a set of system states

(given a structure).

  • Stereotypes are just labels.
slide-32
SLIDE 32

References

– 6 – 2016-11-15 – main –

30/31

slide-33
SLIDE 33

References

– 6 – 2016-11-15 – main –

31/31 Oestereich, B. (2006). Analyse und Design mit UML 2.1, 8. Auflage. Oldenbourg, 8. edition. OMG (2011a). Unified modeling language: Infrastructure, version 2.4.1. Technical Report formal/2011-08-05. OMG (2011b). Unified modeling language: Superstructure, version 2.4.1. Technical Report formal/2011-08-06. Schumann, M., Steinke, J., Deck, A., and Westphal, B. (2008). Traceviewer technical documentation, version 1.0. Technical report, Carl von Ossietzky Universität Oldenburg und OFFIS.