• No results found

Software Design, Modelling and Analysis in UML

N/A
N/A
Protected

Academic year: 2021

Share "Software Design, Modelling and Analysis in UML"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

Software Design, Modelling and Analysis in UML

Lecture 08: Class Diagrams II

2013-11-20

Prof. Dr. Andreas Podelski,Dr. Bernd Westphal

Albert-Ludwigs-Universit¨at Freiburg, Germany

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in –

Contents & Goals

Last Lectures:

• class diagram — except for associations; visibility within OCL type system

This Lecture:

• Educational Objectives: Capabilities for following tasks/questions.

• Please explain this class diagram with associations.

• Which annotations of an association arrow are semantically relevant?

• What’s a role name? What’s it good for?

• What’s “multiplicity”? How did we treat them semantically?

• What is “reading direction”, “navigability”, “ownership”, . . . ?

• What’s the difference between “aggregation” and “composition”?

• Content:

• Study concrete syntax for “associations”.

• (Temporarily) extend signature, define mapping from diagram to signature.

• Study effect on OCL.

• Where do we put OCL constraints?

– 0 8 – 2 0 1 3 -1 1 -2 0 – S p re li m – 2/50

(2)

Associations: Syntax

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in – 3/50

UML Class Diagram Syntax

[Oestereich, 2006]

Geschäftsmitarbeiter Geschäftsmitarbeiter

© 2006 by oose.de GmbH

Aktuelle Fassung, Info und Download: http://www.oose.de/uml UML-NotationsübersichtTeil 1/4

Klassendiagramm operation1() operation2() «interface» Schnittstelle Parametrisier-bare Klasse i:Element Parametrisierte Klasse<Parameter> Aktive Klasse Objekt:Klasse attribut = wert Objekt :Klasse Aktives Objekt Objekt Klasse1 rolle 1 Sichtbarkeit rolle * {ordered} «Stereotyp» Beziehungsname Multiplizität Leserichtung Klasse2 «interface» Schnittstelle-A Anbieter «interface» Schnittstelle-A Nutzer attribut operation() «Stereotyp1» attribut = wert «Stereotyp1, Stereotyp2» Paket::Klasse Sichtbarkeit: + public element # protected element – private element ~ package element Syntax für Attribute:

Sichtbarkeit Attributname : Paket::Typ [Multiplizität Ordnung] = Initialwert {Eigenschaftswerte} Eigenschaftswerte: {readOnly}, {ordered}, {composite}

Syntax für Operationen:

Sichtbarkeit Operationsname (Parameterliste):Rückgabetyp {Eigenschaftswerte} Parameterliste: Richtung Name : Typ = Standardwert Eigenschaftswerte: {query} Richtung: in, out, inout

Klasse AbstrakteKlasse

Objektdiagramm "Stecker" "Buchse" genutzte Schnittstelle Klasse bereitgestellte Schnittstelle Abhängige Klasse Unab-hängige Klasse Abhängigkeit Klasse1 Assoziation Klasse2

Klasse1 Klasse2 qualifizierte Assoziation

Qualifizierer

Klasse1 Vererbung Klasse2

Klasse1 Realisierung Klasse2 Klasse1 gerichtete Assoziation Klasse2

Notiz

Entity Control Boundary

Ganzes Aggregation Teil

Existenz-abhängiges Teil Komposition Assoziations-klasse

Klasse1 Attributierte Assoziation Klasse2

Klasse1 Klasse2 Mehrgliedrige

Assoziation

Klasse3

Anbieter Schnittstelle Nutzer

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 4/50

(3)

UML Class Diagram Syntax

[Oestereich, 2006]

© 2006 by oose.de GmbH

Aktuelle Fassung, Info und Download: http://www.oose.de/uml UML-NotationsübersichtTeil 1/4

operation1() operation2() «interface» Schnittstelle Klasse1 rolle 1 Sichtbarkeit rolle * {ordered} «Stereotyp» Beziehungsname Multiplizität Leserichtung Klasse2 «interface» Schnittstelle-A Anbieter «interface» Schnittstelle-A Nutzer "Stecker" "Buchse" genutzte Schnittstelle Klasse bereitgestellte Schnittstelle Abhängige Klasse Unab-hängige Klasse Abhängigkeit

Klasse1 Assoziation Klasse2

Klasse1 Klasse2

qualifizierte Assoziation Qualifizierer

Klasse1 Vererbung Klasse2

Klasse1 Realisierung Klasse2 Klasse1 gerichtete Assoziation Klasse2

Notiz Ganzes Teil Aggregation Existenz-abhängiges Teil Komposition Assoziations-klasse

Klasse1 Attributierte Assoziation Klasse2

Klasse1 Klasse2 Mehrgliedrige Assoziation Klasse3 Anbieter Schnittstelle Nutzer – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 5/50

UML Class Diagram Syntax

[OMG, 2007b, 61;43]

Figure 7.23 - Examples of navigable ends

b A B 2..5 1..4 a E F 2..5 f 1..4 e C D 2..5 d 1..4 c h G H 2..5 1..4 g I J 2..5 j 1..4 i b A B 2..5 1..4 a E F 2..5 f 1..4 e C D 2..5 d 1..4 c h G H 2..5 1..4 g I J 2..5 j 1..4 i

Figure 7.19 - Graphic notation indicating exactly one association end owned by the association

A B endA * endB * BinaryAssociationAB

Figure 7.20 - Combining line path graphics

A B A B – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 6/50

(4)

What Do We (Have to) Cover?

Anassociationhas

Klasse1 Assoziation Klasse2

Klasse1 Klasse2

qualifizierte Assoziation Qualifizierer

Klasse1 gerichtete Assoziation Klasse2

Klasse1 rolle 1 Sichtbarkeit rolle * {ordered} «Stereotyp» Beziehungsname Multiplizität Leserichtung Klasse2 Ganzes Teil Aggregation Existenz-abhängiges Teil Komposition Assoziations-klasse

Klasse1 Attributierte Assoziation Klasse2

Klasse1 Klasse2

Mehrgliedrige Assoziation

Klasse3

• aname,

• areading direction, and

• at least twoends.

Eachendhas

• arole name,

• amultiplicity,

• a set of properties,

such asunique,ordered, etc.

• aqualifier,

• avisibility,

• anavigability,

• anownership,

• and possibly adiamond.

Wanted: places in the signature to rep-resent the information from the picture.

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 7/50

(Temporarily) Extend Signature: Associations

Onlyfor the course of Lectures 08/09 we assume that each attribute in V

• eitherishv:τ, ξ,expr0, Pviwithτ ∈T (as before),

• oris an associationof the form

hr:hrole1:C1, µ1, P1, ξ1, ν1, o1i,

.. .

hrolen:Cn, µn, Pn, ξn, νn, onii

where

• n≥2(at least two ends),

• r,roleiare justnames,Ci∈C,1≤i≤n,

• themultiplicityµiis an expression of the form

µ::=∗ |N|N..M |N..∗ |µ, µ (N, M ∈N)

• Pi is a set of properties(as before),

• ξ∈ {+,−,#,∼}(as before), • νi∈ {×,−, >}is thenavigability, • oi∈B is theownership. – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 8/50

(5)

(Temporarily) Extend Signature: Associations

Onlyfor the course of Lectures 08/09 we assume that each attribute in V

• eitherishv:τ, ξ,expr0, Pviwithτ ∈T (as before),

• oris an associationof the form

hr:hrole1:C1, µ1, P1, ξ1, ν1, o1i,

.. .

hrolen:Cn, µn, Pn, ξn, νn, onii

where

• n≥2(at least two ends),

• r,roleiare justnames,Ci∈C,1≤i≤n,

• themultiplicityµiis an expression of the form

µ::=∗ |N|N..M |N..∗ |µ, µ (N, M ∈N)

• Pi is a set of properties(as before),

• ξ∈ {+,−,#,∼}(as before),

• νi∈ {×,−, >}is thenavigability,

• oi∈B is theownership.

Alternative syntax for multiplicities:

µ::=N..M |N..∗ |µ, µ (N, M ∈N∪ {∗})

and define∗andN as abbreviations.

Note: N could abbreviate0..N,1..N, orN..N. We use last one.

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 8/50

(Temporarily) Extend Signature: Basic Type Attributes

Also onlyfor the course of this lecture

• we only considerbasic type attributesto “belong” to a class

(to appear inatr(C)),

• associationsare not “owned” by a particular class

(do not appear inatr(C)), but live on their own.

Formally: we only call

(T,C, V,atr)

asignature (extended for associations)if

atr:C →2 {v∈V|v:τ,τ T} . – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 9/50

(6)

From Association Lines to Extended Signatures

C1 C2 .. . Cn

r Ci Pi ξi rolei µi maps to hr:hrole1:C1, µ1, P1, ξ1, ν1, o1i .. . hrolen:Cn, µn, Pn, ξn, νn, onii oi =    1 , if Ci 0 , if Ci νi=          × , if × Ci − , if Ci > , if Ci – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 10/50

Association Example

C D x:Int •× r 0.. +n 0.. −c Signature: S =({Int},{C, D},{x:Int, hr:hc:D,0..∗,{unique},−,×,0i, hn:C,0..∗,{unique},+, >,1ii}, {C7→ ∅, D7→ {x}}) – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 11/50

(7)

What If Things Are Missing?

Most components of associations or association end may be omitted.

For instance[OMG, 2007b, 17], Section 6.4.2, proposes the following rules:

• Name: Use

AhC1i · · · hCni

if the name is missing.

Example:

C D

A C D

for C D

• Reading Direction: no default.

• Role Name: use the class name at that end in lower-case letters

Example:

C c d D for C D

Other convention: (used e.g. by modelling tool Rhapsody)

C itsC itsD D for C D

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 12/50

What If Things Are Missing?

• Multiplicity: 1

In my opinion, it’s safer to assume0..1or∗if there are no fixed, written,

agreed conventions (“expect the worst”).

• Properties: ∅

• Visibility: public

• Navigability and Ownership: not so easy. [OMG, 2007b, 43]

“Various options may be chosen for showing navigation arrows on a diagram. In practice, it is often convenient to suppress some of the arrows and crosses and just show exceptional situations:

Show all arrows and x’s. Navigation and its absence are made completely explicit.

Suppress all arrows and x’s. No inference can be drawn about navigation. This is similar to any situation in which information is suppressed from a view.

Suppress arrows for associations with navigability in both directions, and show arrows only for associations with one- way navigability.

In this case, the two-way navigability cannot be distinguished from situations where there is no navigation at all; however, the latter case occurs rarely in practice.” – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 13/50

(8)

Wait, If Omitting Things...

• ...is causing so much trouble (e.g. leading to misunderstanding),

why does the standard say “In practice, it is often convenient. . . ”?

Is it a good idea to trade conveniencefor precision/unambiguity?

It depends.

• Convenience as such is a legitimate goal.

• In UML-As-Sketch mode, precision “doesn’t matter”,

so convenience (for writer) can even be a primary goal.

• In UML-As-Blueprint mode,precision is theprimary goal.

And misunderstandings are in most cases annoying. But: (even in UML-As-Blueprint mode)

If all associations in your model have multiplicity∗,

then it’s probably a good idea not to write all these∗’s.

So: tell the reader about it and leave out the∗’s.

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs yn – 14/50

(9)

Association Semantics

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in – 15/50

Overview

What’s left? Namedassociation with at least two typed ends, each having

• arole name, • amultiplicity, • a set of properties, • avisibility, • a navigability, and • anownership. The Plan:

• Extendsystem states, introduce so-calledlinksas instances of

associations — depends onnameand ontypeandnumberof ends.

• Integraterole nameandmultiplicityinto OCL syntax/semantics.

• Extendtyping rulesto care for visibilityandnavigability

• Considermultiplicityalso as part of the constraintssetInv(CD).

• Properties: for now assumePv ={unique}. • Properties(in general) andownership: later.

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o co ve r – 16/50

(10)

Association Semantics: The System State Aspect

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in – 17/50

Associations in General

Recall: We consider associations of the following form:

hr:hrole1:C1, µ1, P1, ξ1, ν1, o1i, . . . ,hrolen:Cn, µn, Pn, ξn, νn, onii

Only these parts are relevant for extended system states:

hr:hrole1:C1, , P1, , , i, . . . ,hrolen:Cn, , Pn, , , i

(recall: we assume P1=Pn={unique}).

The UML standard thinks of associations asn-ary relations

which “live on their own” in a system state.

That is,links(=association instances)

• do notbelong (in general) to certain objects (in contrast to pointers, e.g.)

• are “first-class citizens” next to objects,

• are (in general)notdirected (in contrast to pointers).

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs em – 18/50

(11)

Links in System States

hr:hrole1:C1, , P1, , , i, . . . ,hrolen:Cn, , Pn, , , i

Onlyfor the course of lectures 07/08 we change the definition of system states:

Definition. Let D be a structure of the (extended) signature

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

Asystem stateofS wrt.D is a pair(σ, λ)consisting of

• a type-consistent mapping

σ:D(C)9(atr(C)9D(T)),

• a mappingλwhich assigns each association

hr:hrole1:C1i, . . . ,hrolen:Cnii ∈V a relation

λ(r)⊆D(C1)× · · · ×D(Cn)

(i.e. a set of type-consistentn-tuples of identities).

– 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs em – 19/50

(12)

Association/Link Example

C D x:Int •× 0.. n Signature: S = ({Int},{C, D},{x:Int, hA C D:hc:C,0..∗,+,{unique},×,1i, hn:D,0..∗,+,{unique}, >,0ii}, {C 7→ ∅, D7→ {x}})

Asystem stateofS (some reasonableD) is(σ, λ) with: σ={1C7→ ∅,3D7→ {x7→1},7D 7→ {x7→2}} λ={A C D7→ {(1C,3D),(1C,7D)}} – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs em – 20/50

Extended System States and Object Diagrams

Legitimate question: how do we represent system states such as

σ={1C7→ ∅,3D7→ {x7→1},7D 7→ {x7→2}} λ={A C D7→ {(1C,3D),(1C,7D)}} asobject diagram? – 0 8 – 2 0 1 3 -1 1 -2 0 – S a ss o cs em – 21/50

(13)

References

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in – 49/50

References

[Oestereich, 2006] Oestereich, B. (2006). Analyse und Design mit UML 2.1, 8. Auflage. Oldenbourg, 8. edition.

[OMG, 2007a] OMG (2007a). Unified modeling language: Infrastructure, version 2.1.2. Technical Report formal/07-11-04.

[OMG, 2007b] OMG (2007b). Unified modeling language: Superstructure, version 2.1.2. Technical Report formal/07-11-02.

– 0 8 – 2 0 1 3 -1 1 -2 0 – m a in – 50/50

References

Related documents

Finally, after the motion of the particles and bubbles is developing in the course of time (Figure 13), following conclusions can be made: gas bubbles mostly

The latter meth- od was employed in the present study: correlation was used in showing the relationship between climatic parameters and crop yield, the trend and variation

Our study used mixed methods ( Figure 1 ) to identify and assess the status of workforce diversity in the dental specialties and to understand the pipeline of underrepresented

Details of the classification and amount of each element of the remuneration of senior executives (excluding the Managing Director and Chief Executive Officer) who received the

For the ROI-based analysis, we performed separate multiple linear regression analyses of left and right hippocampal grey matter volume on total recall, primacy, and recency

Favorite teams and sell my lady was well as well done, now sign up to any of ticketmaster credit code can do that show Longest run of buying tickets on the story of the button on

encrasicolus ) and sardine ( Sardina pilchardus ). The abundance indices estimated by all MEDIAS parties provided in the DCF report should include both NASC and Biomass

W e have audited the Annexed Balance Sheet of Indian Medical Association National Social Security Scheme, Ahmedabad as at 31st March, 2004 and Income and Expenditure Account for