Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul...

23
Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause

Transcript of Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul...

Page 1: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

The Models are the Code -Executable UML

Lecture 5 - Attributes and Relations

Paul Krause

Page 2: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Lecture 5 - Attributes and Relations

Continue with properties of attributes

Introduction to xUML relationship types

Page 3: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Properties of Attributes

Purpose

Identification role

Dependency on other attributes

Value assignment

Universal meaning

Page 4: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Dependence on other attributes

Rule 1:

The values of all non-identifying attributes depend only on the identifier

Spot Light

Colour temperatureIntensityx Locationy Locationz Location

Change SpotLight ID (Implicit)and the values of any of the other

attributes may change.But the value of any other attribute

may be changed independently of theothers.

Page 5: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Dependence on other attributes

Contact

NameHome addressBirthdateCompany nameWork address

Change the Company nameand the address must (normally)

change

Page 6: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Dependency on other attributes

Contact

NameHome addressBirth date

Company

Name {I}AddressPhoneCafeteria quality

R10..*employs

0..1works at

Page 7: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Dependence on other attributes

Rule 2:

Each non-identifying attribute must depend on the whole ID

Automated Vehicleon Route

Vehicle ID {I}Route ID {I}Accumulated delayEstimated completion timeBattery charge

{These two

attributes depend

on the whole ID

This attribute dependsonly on Vehicle ID

Page 8: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Dependence on other attributes

Automated Vehicleon Route

Vehicle ID {I, R1}Route ID {I}Accumulated delayEstimated completion time

Vehicle

ID {I}WeightBattery chargeTime since last service

R10..1is inservice as

1uses

Page 9: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Value Assignment

Automated Vehicleon Route

Vehicle ID {I, R1}Route ID {I}Accumulated delayEstimated completion time

Page 10: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Value Assignment

Automated Vehicleon Route

Vehicle ID {I, R1}Route ID {I}Accumulated delayEstimated completion time }

The values assigned to thesenon-identifier attributes can bechanged to any other legal value

Page 11: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Value Assignment

Automated Vehicleon Route

Vehicle ID {I, R1}Route ID {I}Accumulated delayEstimated completion time

But we can’t, for example, changethe value of the Route ID (an

identifier attribute) without checkingthat a duplicate instance

is not being created

Page 12: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Value Assignment - Computational dependence

Shaft Encoder

Mark spacingPulse rate

Motor Shaft

\Rotational speedR11

rotational speed isdetected by

1detects

rotationalspeed of

The “\” indicates this attributeis computationally dependent

on other attributes in the model

self.Rotational_speed =my_Shaft_Encoder.Mark_spacing *my_Shaft_Encoder.Pulse_rate

Page 13: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Universal meaning?

Does an attribute always have meaning in a specific class?

If it does not, then again you may need to modify the class model: Never applicable for some instances

then use a generalisation hierarchy and specialise these instances

Not applicable at some momentThen specialise the class into distinct roles

Page 14: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Universal meaning?

Landing Gear

ManufacturerWeight

UninstalledLanding Gear

InstalledLanding Gear

retracted status

R1

Page 15: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Executable UML Relationship Types

Binary Non-reflexiveBinary reflexive

Association ClassGeneralisation

{disjoint, complete}

Page 16: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Lecture 5 - Associations

Naming associations Binary non-reflexive associations

Binary reflexive associations

Association Classes

Loops and constraints

Page 17: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Naming Associations

cardio_7bcardio_7b

cardio_7bcardio_7b

cardio_7b

cardio_1b

def_87c

currently loaded

default

Library ofpresets on

local hard drive

preset files

Page 18: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Application Note

A medical ultra-sound scanner station operates with hundreds of parameter settings.

A complete collection of parameters with initial value settings can be stored in a preset file.

The capabilities of the ultrasound scanner depend entirely on what preset file has been loaded.

Upon power up, the scanner automatically loads values from whichever preset file has been designated as the station default.

Leon Starr - How to Build Class Models

Page 19: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Text Book Solution

Preset File

Name

Station

Serial number {I}

uses

*

• Which preset is currently controlling the station?

• How do we ensure only one preset is controlling the station at a time?

• Which preset file is loaded at power up?

Page 20: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Application rules

At any time, a Station is using the parameter values from one Preset File

Exactly one Preset File is designated as the default for a given station

Any Preset File may be designated as the default for a given Station

Page 21: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Try harder!

Preset File

Name

Station

Serial number {I}

is usingthe values

from

1

suppliesvalues tocontrol

0..1

Page 22: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

Default file

Preset File

Name

Station

Serial number {I}

uses valuesby default

from

1

is defaultsource ofvalues for

0..1

Page 23: Executable UML The Models are the Code - Executable UML Lecture 5 - Attributes and Relations Paul Krause.

Executable UML

The complete solution

Preset File

Name

Station

Serial number {I}is using

the valuesfrom

1

suppliesvalues tocontrol

0..1

uses valuesby default

from

1

is defaultsource ofvalues for

0..1

R1

R2