49
UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal Foundations of Software Engineering

UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

UML Class Diagrams 2

Martin Nečaský

Dept. of Software Engineering

Faculty of Mathematics and Physics

Charles University in Prague

Formal Foundations of Software Engineering

Page 2: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Previous Lecture Reminder

What are UML class diagrams?

basic constructs

classes

class properties (attributes and association ends)

binary and n-ary associations

association classes

navigability

multiplicities

property modifiers

Formal Foundations of Software Engineering

Page 3: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Previous Lecture Reminder

Formal Foundations of Software Engineering

class Conceptual Mo...

Person

+ name: String

+ email: String [0..*]

+ phone: String [0..*]

+ registrationDate: Date

+ homepage: URL

+ dblp: URL

Team

+ name: String

+ homepage: URL

+ notify(Project) : void

Project

+ name: String

+ email: String [0..*]

+ description: String

+ homepage: URL

+ status: int

+ close() : void

Institution

+ officialTitle: String

+ homepage: URL

Researcher

+ topic: String [1..*]

+ degree: DegreeType = assistant_prof

Student

Univ ersity

«enumeration»

DegreeType

researcher

assistant_prof

associated_prof

full_prof

Worker

Membership

+ from: date

+ to: date

+ position: Position

«enumeration»

Position

manager

developer

analyst

+principalProject

0..*+principalPartner

0..1

+managedTeam

0..*

+manager

0..1

+partner

0..*

{ordered}0..*

0..*

+member 1..*

{non-unique}

0..*

0..*

0..*

+colleague

0..*

0..1

0..*

0..*

+employer

0..*

0..*

0..10..1

Page 4: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Formal model of Properties

Formal Foundations of Software Engineering

class Property

Property

Class

Association

StructuralFeature

TypedElement

+class 0..1

+ownedAttribute *

+owningAssociation

0..1

+ownedEnd

*

+association

0..1

+navigableOwnedEnd

*

+association

0..1

+memberEnd 2..*

Page 5: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Attributes vs. Associations

attribute property related to a

class by ownedAttribute

association end property related to an

association by memberEnd

note: property can be both attribute and association end; such property must be owned by the class

note: association ends of associations with more than two ends must be owned by the associations

Formal Foundations of Software Engineering

class Property

Property

Class

Association

StructuralFeature

TypedElement

+class 0..1

+ownedAttribute *

+owningAssociation

0..1

+ownedEnd

*

+association

0..1

+navigableOwnedEnd

*

+association

0..1

+memberEnd 2..*

Page 6: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Attributes vs. Associations

Person instance of Class

name instance of Property related to Person by

ownedAttribute

String value of type (inherited

from TypedElement)

Formal Foundations of Software Engineering

class Conceptual Mo...

Person

+ name: String

+ email: String [0..*]

+ phone: String [0..*]

+ registrationDate: Date

+ homepage: URL

+ dblp: URL

Team

+ name: String

+ homepage: URL

+ notify(Project) : void

Project

+ name: String

+ email: String [0..*]

+ description: String

+ homepage: URL

+ status: int

+ close() : void

Institution

+ officialTitle: String

+ homepage: URL

Researcher

+ topic: String [1..*]

+ degree: DegreeType = assistant_prof

Student

Univ ersity

«enumeration»

DegreeType

researcher

assistant_prof

associated_prof

full_prof

Worker

Membership

+ from: date

+ to: date

+ position: Position

«enumeration»

Position

manager

developer

analyst

+principalProject

0..*+principalPartner

0..1

+managedTeam

0..*

+manager

0..1

+partner

0..*

{ordered}0..*

0..*

+member 1..*

{non-unique}

0..*

0..*

0..*

+colleague

0..*

0..1

0..*

0..*

+employer

0..*

0..*

0..10..1

class Property

Property

Class

Association

StructuralFeature

TypedElement

+class 0..1

+ownedAttribute *

+owningAssociation

0..1

+ownedEnd

*

+association

0..1

+navigableOwnedEnd

*

+association

0..1

+memberEnd 2..*

Attribute

Page 7: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Attributes vs. Associations

Institution, Address instance of Class

anonymous instance of Association

address instance of Property related to Institution by ownedAttribute related to anonymous by memberEnd owned by Institution

Formal Foundations of Software Engineering

class Attribute

Institution

+ officialTitle: String

+ homepage: URL

+ address: Address [0..*] class Association

Institution

+ officialTitle: String

+ homepage: URL

Address

+ street: String

+ city: String

+ country: String

1

+address

0..*

class Property

Property

Class

Association

StructuralFeature

TypedElement

+class 0..1

+ownedAttribute *

+owningAssociation

0..1

+ownedEnd

*

+association

0..1

+navigableOwnedEnd

*

+association

0..1

+memberEnd 2..*

AttributeAttribute &

Association End

Page 8: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Attributes vs. Associations

Person, Institution instances of Class

anonymous instance of Association

employee, employer instances of Property related to anonymous by

memberEnd and ownedEnd owned by anonymous

Formal Foundations of Software Engineering

class Property

Property

Class

Association

StructuralFeature

TypedElement

+class 0..1

+ownedAttribute *

+owningAssociation

0..1

+ownedEnd

*

+association

0..1

+navigableOwnedEnd

*

+association

0..1

+memberEnd 2..*

class BidirectionalAssociation

Person Institution+employee

1..*

+employer

0..*

AttributeAssociation

Ends

Page 9: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

UML specification property represents a declared state of one or more

instances in terms of a named relationship to one or more values

mathematically property P is a function

𝑃: 𝐼(𝐶1) × ⋯× 𝐼(𝐶𝑛) → 2𝑇

where• classes C1,..., Cn are determined by the owner of P

– {C1,..., Cn} is called context of P

• I(Ci) denotes the set of instances of Ci

• min <= |P(i1, ..., in)| <= max where (min, max) is the multiplicity of P

• P(i1, ..., in) is an (un)ordered set or multi-set– depends on modifiers assigned to P

Formal Foundations of Software Engineering

Page 10: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

Formal Foundations of Software Engineering

class Conceptual Mo...

Person

+ name: String

+ email: String [0..*]

+ phone: String [0..*]

+ registrationDate: Date

+ homepage: URL

+ dblp: URL

Team

+ name: String

+ homepage: URL

+ notify(Project) : void

Project

+ name: String

+ email: String [0..*]

+ description: String

+ homepage: URL

+ status: int

+ close() : void

Institution

+ officialTitle: String

+ homepage: URL

Researcher

+ topic: String [1..*]

+ degree: DegreeType = assistant_prof

Student

Univ ersity

«enumeration»

DegreeType

researcher

assistant_prof

associated_prof

full_prof

Worker

Membership

+ from: date

+ to: date

+ position: Position

«enumeration»

Position

manager

developer

analyst

+principalProject

0..*+principalPartner

0..1

+managedTeam

0..*

+manager

0..1

+partner

0..*

{ordered}0..*

0..*

+member 1..*

{non-unique}

0..*

0..*

0..*

+colleague

0..*

0..1

0..*

0..*

+employer

0..*

0..*

0..10..1

if the owner of P is a class C then n = 1 C1 = C

person A

“John Doe”

name

[email protected]

[email protected]

email

phone

Page 11: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

Formal Foundations of Software Engineering

institution A

address 1

address 2

address

class Association

Institution

+ officialTitle: String

+ homepage: URL

Address

+ street: String

+ city: String

+ country: String

1

+address

0..*

if the owner of P is a class C then n = 1 C1 = C

Page 12: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

Formal Foundations of Software Engineering

if the owner of P is an association R then n = |R.memberEnd| - 1 C1, ..., Cn = R.memberEnd.type \ P.type

person A

institution 1

institution 2employer

class BidirectionalAssociation

Person Institution+employee

1..*

+employer

0..*

institution 3

Page 13: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

Formal Foundations of Software Engineering

if the owner of P is an association R then n = |R.memberEnd| - 1 C1, ..., Cn = R.memberEnd.type \ P.type

project Aperson 1

person 2worker

person 3

class Nary

Person

- name: String

Team

Project

+project 0..1

+team

0..1

+worker

0..*

team α

Page 14: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Values

isOrdered isUnique Collection Type

false true set

true true list (ordered set)

false false bag (multi-set)

true false sequence (ordered multi-set)

Formal Foundations of Software Engineering

P(i1, ..., in) is an (un)ordered set or multi-set depends on modifiers

assigned to P {ordered} P.isOrdered =

true (default false) {non-unique} P.isUnique

= false (default true)

class PropertiesDetail

Property

+ isDerived: boolean = false

+ isReadOnly: boolean = false

+ isDerivedUnion: boolean = false

+ aggregation: AggregationKind = none

+ isID: boolean = false

ValueSpecification MultiplicityElement

- isOrdered: boolean

- isUnique: boolean

0..*

+subsettedProperty 0..*

+property 0..*+redefinedProperty 0..*

+defaultValue

0..1

+owningProperty0..1

+upperValue

0..1

+owningUpper

0..1

+lowerValue

0..1

+owningLower

0..1

Page 15: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Specializing Attributes and

Associations common misunderstanding is that only classes

can be specialized

specializing attributes and associations is also possible!

via property subsetting and redefining

Formal Foundations of Software Engineering

class PropertiesDetail

Property

+ isDerived: boolean = false

+ isReadOnly: boolean = false

+ isDerivedUnion: boolean = false

+ aggregation: AggregationKind = none

+ isID: boolean = false 0..*

+subsettedProperty 0..*

+property 0..*+redefinedProperty 0..*

Page 16: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Subsetting and Redefining

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 17: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Subsetting

set of instances of a property Psub is a subset of a set of instances of another property P

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 18: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Subsetting – Constraints

name of Psub must differ from the name of P

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 19: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Subsetting – Constraints

type of Psub must be the same as the type of P or it must be its specialization

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 20: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Subsetting – Constraints

upper multiplicity of Psub must be less than the upper multiplicity of P lower multiplicity is not restricted, i.e. multiplicity of Psub

does not necessarily need to be a sub-interval of the multiplicity of P

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 21: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Property Subsetting – Constraints

context of Psub must conform to the context of P

(∀𝐶𝑠𝑢𝑏 ∈ 𝑐𝑜𝑛𝑡𝑒𝑥𝑡(𝑃𝑠𝑢𝑏))(∃𝐶 ∈ 𝑐𝑜𝑛𝑡𝑒𝑥𝑡(𝑃))

(𝐶 = 𝐶𝑠𝑢𝑏 ∨ 𝐶 𝑖𝑠 𝑔𝑒𝑛𝑒𝑟𝑎𝑙𝑖𝑧𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝐶𝑠𝑢𝑏)

Formal Foundations of Software Engineering

Page 22: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Redefining

specific property Pred redefines a general property P in order to augment, constraint or override P

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 23: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Redefining – Constraints

P must be inherited by the type of Pred from its general class

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 24: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Redefining – Constraints

multiplicity of Pred is a sub-interval of the multiplicity of P

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 25: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Redefining – Constraints

name, visibility and default value of the property can be redefined in any way

Formal Foundations of Software Engineering

class Subsetting

Team Person

+ skill: string [0..*]

Researcher

+ skill: ResearchSkill [1..*]

+ researchField: ResearchSkill [1..*]

+team

0..*

+member

1..*

+externalTeam

0..*

{subsets team} +externalMember

0..*

{subsets member}

+leaderOf 0..*

{subsets team}

+leader

0..1

{subsets member}

{redefines skill}{subsets skill}

Page 26: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Navigability

association R is navigable in an end E from the opposite ends iff E is

owned by its class, or

navigable owned end of R

Formal Foundations of Software Engineering

class Property

StructuralFeature

Property

Association

Class

+owningAssociation

0..1

{subsets

association}

+ownedEnd

*

{subsets memberEnd}

+association

0..1

{subsets

owningAssociation}

+navigableOwnedEnd

*

{subsets ownedEnd}

+association

0..1

+memberEnd 2..*

+class 0..1

+ownedAttribute *

Page 27: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Navigability

anonymousassociation is navigable in address from the opposite association end

address is owned by Institution

Formal Foundations of Software Engineering

class Association

Institution

+ officialTitle: String

+ homepage: URL

Address

+ street: String

+ city: String

+ country: String

1

+address

0..*

class Property

StructuralFeature

Property

Association

Class

+owningAssociation

0..1

{subsets

association}

+ownedEnd

*

{subsets memberEnd}

+association

0..1

{subsets

owningAssociation}

+navigableOwnedEnd

*

{subsets ownedEnd}

+association

0..1

+memberEnd 2..*

+class 0..1

+ownedAttribute *

Page 28: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Property Navigability

anonymousassociation is navigable in worker from the opposite association ends worker is navigable

owned end of anonymous

Formal Foundations of Software Engineering

class Property

StructuralFeature

Property

Association

Class

+owningAssociation

0..1

{subsets

association}

+ownedEnd

*

{subsets memberEnd}

+association

0..1

{subsets

owningAssociation}

+navigableOwnedEnd

*

{subsets ownedEnd}

+association

0..1

+memberEnd 2..*

+class 0..1

+ownedAttribute * class Nary

Person

- name: String

Team

Project

+project 0..1

+team

0..1

+worker

0..*

Page 29: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Aggregations and Compositions

Formal Foundations of Software Engineering

class PropertiesDetail

Property

+ isDerived: boolean = false

+ isReadOnly: boolean = false

+ isDerivedUnion: boolean = false

+ aggregation: AggregationKind = none

+ isID: boolean = false

«enumeration»

AggregationKind

none

shared

composite

+property 0..*+redefinedProperty 0..*

0..*

+subsettedProperty 0..*

Page 30: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Aggregations and Compositions

aggregation or, also called, shared aggregation

part-of relationship

parts can be shared by different owners

Formal Foundations of Software Engineering

class Aggregation

Person TeamInstitution+member

1..* 0..*0..*

+employee

1..*

Page 31: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Aggregations and Compositions

composition or, also called, composite aggregation

part-of relationship parts cannot be shared by different owners (exclusive

ownership)

parts cannot exist without owners

upper bound must be 1 (or unspecified)

Formal Foundations of Software Engineering

class Aggregation

Section

Book

ArticleChapter

1

1..*

0..1

1..*

0..1

1..*

Page 32: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Specialization/Generalization

generalization is a taxonomic relationship between a more general class and a more specific class

each instance of the specific class is also an instance of the general class (inheritance)

features specified for instances of the general class are implicitly specified for instances of the specific class

constraints applying to instances of the general class also apply to instances of the specific class

Formal Foundations of Software Engineering

Page 33: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Specialization/Generalization

Formal Foundations of Software Engineering

class SimpleGeneralization

Person

- name: String

- email: String

- phone: String

Student

- schoolWork: URL

ResearcherTeacher Practicioner

- project: URL [1..*]

Lecture

- title: String

Paper

- title: String

- journal: URL

1..* 1..*

Page 34: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Generalization Sets

Formal Foundations of Software Engineering

class Adv ancedGeneralizati...

Person

Student Teacher Researcher Practicioner

Biologist Chemist SoftwareEngineer

Male

Female

PersonKind PersonKind PersonKind PersonKind

SpecializationSpecialization Specialization

Gender

Gender

{incomplete, overlapping}

{complete, overlapping}

{complete, disjoint}

Page 35: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Power Types

generalization set can be associated with a class whose instances are specific classes involved in the generalization set

What are power types good for?

Formal Foundations of Software Engineering

class PowerType

Person

Student

ResearcherTeacherPracticioner

PersonKindType PortalConfigurationExpertProfileType

PersonKindPersonKind PersonKind

PersonKind

0..*

1

0..* 10..*1..*

:PersonKindType

Page 36: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Operations

behavioral feature action that can be performed on class instances

<operation> ::=

[<visibility>] <name>

‘(’ [<parameter-list>] ‘)’

[‘:’ [<return-type>] [‘[‘ <multiplicity> ‘]’]

[‘{’ <oper-property> [‘,’ <oper-property>]* ‘}’] ]

<oper-property> indicates various properties of the operation redefines <oper-name>: operation redefines inherited

operation query: operation does not change the state of the system

(read-only) if max multiplicity > 1 then

• ordered: return values are ordered• unique: return values do not contain duplicities

Formal Foundations of Software Engineering

Page 37: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Operations

may be supplied with *-conditions

pre-condition

• condition which must be true before the operation is invoked

post-condition

• condition which must be true when the invocation of the operation completes successfully

body-condition

• condition which constraints the return result

• may be overridden

Formal Foundations of Software Engineering

Page 38: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Operations

Formal Foundations of Software Engineering

+ getName(): String

+ setName(_n: String)

+ addAddress(_a: Address, position: int)

+ getAddresses(): Address [1..3] {ordered}

Person

Page 39: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Enumerations

Formal Foundations of Software Engineering

class Conceptual Mo...

Researcher

+ topic: String [1..*]

+ degree: DegreeType = assistant_prof

«enumeration»

DegreeType

researcher

assistant_prof

associated_prof

full_prof

Page 40: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Stereotypes

disadvantage of a graphical notation (like UML) is that you have to remember what the symbols mean

to reduce the number of symbols, UML introduces the notion of stereotypes stereotype is a string keyword

if you need to model something which is not part of UML but is similar to a UML construct, use that construct and label it with a keyword

<<stereotype>>

Formal Foundations of Software Engineering

Page 41: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Stereotypes

profile = set of stereotypes suitable for certain purpose, e.g.

profile for modeling schemas of relational databases

profile for modeling XSD XML Schemas

Formal Foundations of Software Engineering

Page 42: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Stereotypes

Formal Foundations of Software Engineering

class PSM_RELATIONAL

Contract

«column»

* referenceNumber: NUMBER(8)

* title: VARCHAR2(50)

description: CLOB

* startDate: DATE

* endDate: DATE

* estimatedPrice: NUMBER(9)

agreedPrice: NUMBER(9)

actualPrice: NUMBER(9)

numberOfTenders: NUMBER(2)

*PK contractId: NUMBER(8)

*FK contractingAuthorityId: NUMBER(8)

FK awardedSupplierId: NUMBER(8)

*FK mainAddressId: NUMBER(8)

FK tenderAddressId: NUMBER(8)

FK parentContractId: NUMBER(8)

«FK»

+ FK_Contract_Address(NUMBER)

+ FK_Contract_Address(NUMBER)

+ FK_Contract_Contract(NUMBER)

+ FK_Contract_Organization(NUMBER)

+ FK_Contract_Organization(NUMBER)

«PK»

+ PK_Contract(NUMBER)

«unique»

+ UQ_Contract_referenceNumber()

Organization

«column»

* legalName: VARCHAR2(50)

* officialNumber: NUMBER(9)

*PK organizationId: NUMBER(8)

*FK addressId: NUMBER(8)

«FK»

+ FK_Organization_Address(NUMBER)

«PK»

+ PK_Organization(NUMBER)

«unique»

+ UQ_Organization_officialNumbe(NUMBER)Tender

«column»

* estimatedEndDate: DATE

* offeredPrice: NUMBER(9)

*PK tenderId: NUMBER(8)

*FK tenderingSupplierId: NUMBER(8)

*FK tenderedContractId: NUMBER(8)

«FK»

+ FK_Tender_Contract(NUMBER)

+ FK_Tender_Organization(NUMBER)

«PK»

+ PK_Tender(NUMBER)

Address

«column»

streetName: VARCHAR2(50)

streetNumber: VARCHAR2(50)

city: VARCHAR2(50)

country: VARCHAR2(50)

*PK addressId: NUMBER(8)

«PK»

+ PK_Address(NUMBER)

ItemType

«column»

*PK code: NUMBER(8)

* title: VARCHAR2(50)

«PK»

+ PK_ItemType(NUMBER)

Item

«column»

* code: NUMBER(8)

FK contractId: NUMBER(8)

«FK»

+ FK_Item_Contract(NUMBER)

+ FK_Item_ItemType(NUMBER)

+FK_Contract_Organization 0..*

(awardedSupplierId = organizationId)

«FK»

+PK_Organization 1

+FK_Tender_Organization 0..*

(tenderingSupplierId = organizationId)

«FK»

+PK_Organization

1

+FK_Tender_Contract 0..*

(tenderedContractId = contractId)«FK»

+PK_Contract

1

+FK_Contract_Organization

0..*

(awardedSupplierId = organizationId)

«FK»

+PK_Organization

1

+FK_Contract_Address

0..*

(tenderAddressId = addressId)

«FK»

+PK_Address1

+FK_Contract_Address

0..*

(tenderAddressId = addressId)

«FK»

+PK_Address 1

+FK_Organization_Address

0..*

(addressId = addressId)

«FK»

+PK_Address 1

+FK_Item_Contract

0..*(contractId = contractId)

«FK»

+PK_Contract

1

+FK_Item_ItemType0..*

(contractId = code)

«FK»

+PK_ItemType 1

+FK_Contract_Contract

0..*

(parentContractId = contractId)

«FK»

+PK_Contract

1

Page 43: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Dependencies

class responsibility (sometimes called functionality) each class is responsible for something in the software

application

sometimes a class cannot handle all expected functionality class A asks other classes B1, ..., Bn for help

A is called client

B1, ..., Bn are called suppliers

relationship between client and supplier is called dependency

Formal Foundations of Software Engineering

Page 44: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Dependencies

dependency is a relationship that signifies that a client requires a supplier for its specification or implementation semantics of the client is not complete without the

supplier

modification of the supplier may impact the client

Formal Foundations of Software Engineering

Page 45: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Dependencies

Formal Foundations of Software Engineering

class Dependencies

PIM::Organization

- legalName

- officialNumber

PSM_RELATIONAL::Organization

«column»

* legalName: VARCHAR2(50)

* officialNumber: NUMBER(9)

*PK organizationId: NUMBER(8)

*FK addressId: NUMBER(8)

«FK»

+ FK_Organization_Address(NUMBER)

«PK»

+ PK_Organization(NUMBER)

«unique»

+ UQ_Organization_officialNumbe(NUMBER)

«abstraction» class GUI Mo...

EntityList

«interface»

List

Realization

Page 46: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Class Dependencies

Formal Foundations of Software Engineering

© http://www.uml-diagrams.org

Page 47: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Interfaces and Abstract Classes

abstract class is a class that cannot be directly instantiated

instantiate their specific classes (if not abstract as well)

may or may not have one or more abstract operations

• but abstract class may have sense even without abstract operations

interface is a class that has no implementation

all its features are abstract

Formal Foundations of Software Engineering

Page 48: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Interfaces and Abstract Classes

Formal Foundations of Software Engineering

class InterfacesAbstract

«interface»

Paintable

+ draw() : void

+ color(Color) : void

+ resize(int) : void

Shape

- x: int

- y: int

- color: Color

+ draw() : void

+ color(Color) : void

+ resize(int) : void

+ getArea() : Area

ViewSquare

- sizeX: int

- sizeY: int

+ draw() : void

+ resize(int) : void

+ getArea() : Area

Circle

- radius: int

+ draw() : void

+ resize(int) : void

+ getArea() : Area

«use»

Abstract class

Abstract operation

Interface

Implementation

Dependency(requires)

Page 49: UML Class Diagrams 2 · 2020. 12. 10. · UML Class Diagrams 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague Formal

Few Recommendations

strictly distinguish conceptual and implementation level of modeling

conceptual level is for all stakeholders requirements analysis

software level is for developers design and implementation programming code, or its skeleton, can be generated different schemas for different kinds of developers (e.g. database,

application logic, GUI, ...) see Model-Driven Development

at conceptual level be scope of navigability visibility operations types may also be off importance

Formal Foundations of Software Engineering