executable uml the models are the code - executable uml lecture 4 - how to build class models paul...

29
Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Upload: darleen-dalton

Post on 26-Dec-2015

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

The Models are the Code -Executable UML

Lecture 4 - How to Build Class Models

Paul Krause

Page 2: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Lecture 4 - How to Build Class Models

Specifications vs Things

Interactions

Roles working within our modelling goals

Attributes

Page 3: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Specification Classes

Aircraft Specification

Model number {I}Stall profileWeightWingspanFuel consumption

Aircraft

Registration number {I}Maintenance statusAssigned pilotAssigned mechanicHours flown

1

design is specified by

0..*

specifiesdesign of

R1

Abstract

Properties commonto a specific aircraft type

Concrete

Properties commonto a specific aircraft instance

Distinctlifecycles and

properties

Page 4: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Specification Pattern

Widget Specification

Model number {I}

Widget

Serial number {I}

1

design is specified by

0..*

specifiesdesign of

R1

Abstract Concrete

design characteristics,references to sub-specificationsor other related specifications

characteristics that vary fromwidget to widget, even when the

widgets are defined by thesame widget specification

Will rarely need astate model to define

its behaviour

Will normally need astate model to define

its behaviour

Page 5: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Interaction Classes

Passenger

NamePhone number

Flight

Number {I}Airline {I}Departure dateDeparture timeDeparture airportArrival dateArrival timeArrival airport

0..*

is reservedfor

0..*

reserves

R1

Seat Assignment

????

Page 6: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Interaction Classes

Passenger

NamePhone number

Flight

Number {I}Airline {I}Departure dateDeparture timeDeparture airportArrival dateArrival timeArrival airport

0..*

is reservedfor

0..*

reserves

R1

Reservation

Ticket number {I}Airline {I, R1}CostClassSeat assignment

Page 7: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Role Classes

Wafer Inspection Station0..*

contains

0..1

is loadedinto

R1

Wafer in Process

AllignmentTemperaturePercent scan complete

0..1

directsscanning of

0..1

is scannedaccording to

R2Inspection Script

Area to coverScan method

Delete once Wafer has been unloadedfrom the Inspection Station

Page 8: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Relative Roles

Front SideBack Side

APPLICATION NOTE: The flat shape can rotate in 3D space andmust have exactly one bitmap image on each of its two sides

Page 9: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Multiplicity

Remember, an important characteristic of an association is the number of instances (objects) that participate in each instance of the domain relationship

UML allows specific numbers in a multiplicity relation

In xUML the recommendation is to only use four kinds: unconditional; 1, or 1..* conditional;0..1, or 0..*

Page 10: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Relative Roles

Flat Shape Side1

can be shown by

1..*

can show

R1

ColourTexture

The arguments for making this multiplicity“2” seem compelling,

but can we work within ourmodelling guidelines?

Page 11: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Two 1:1 associations?

Flat Shape

Side1

is front of

1

has front

R1

ColourTexture1

is back of

1

has back

R2

But a Side is either

the Front or the Back of

a Flat Shape, not both!

Page 12: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Two 1:1 associations?

Flat Shape

Side1

is front of

1

has front

R1

ColourTexture1

is back of

1

has back

R2

But a Side is either

the Front or the Back of

a Flat Shape, not both!

Page 13: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Two conditional associations?

Flat Shape

Side0..1

is front of

1

has front

R1

ColourTexture0..1

is back of

1

has back

R2

But this says that a Side

might exist that does not

belong to any Flat Shape!

Page 14: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Two conditional associations?

Flat Shape

Side0..1

is front of

1

has front

R1

ColourTexture0..1

is back of

1

has back

R2

But this says that a Side

might exist that does not

belong to any Flat Shape!

Page 15: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

How about making the Sides attributes?

Flat Shape

Front colourFront textureBack colourBack texture

Bitmap Image?

But we need to model the associationbetween a Bitmap Image and a

specific Side!

Page 16: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Solution: Abstract Positional roles as Classes

Side

ColourTexture

0..*

is drawnon

1

has drawn

R1Bitmap Image

Front Side Back Side

R4

Flat Shape

has on front 1

is front of 1

has on back 1

is back of 1

R2 R3

N.B. We have workedwithin our modellinggoals and produced abetter model!

Page 17: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

What is an Attribute?

“A quality or characteristic inherent in orascribed to someone or something”

The American Heritage Dictionary of the English Language

Star

SAO Number {I}NameDiameterMassDistance

252838Alpha Centauri1.26 M km1.1 x Sun4.3 ly

131881Sirius4.9 M km3 x Sun8.7 ly

Two instances of Star

Attributes:Prototypical characteristics

Attribute Values:Characteristics of a specific instance

Page 18: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Properties of Attributes

Purpose

Identification role

Dependency on other attributes

Value assignment

Universal meaning

Page 19: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Purpose

Here the attribute either names or describes a class instance

Descriptive attributes Size, Capacity, Colour, Stall speed

Naming attributes Discovered names - Company name, Floor

number, Driver’s licence number Invented names - Pump ID, Transaction ID, Event

IDUsing “ID” as a suffix makes it clear these

names are the invention of an analyst

Page 20: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Identification role

Every instance of a class is unique

Consequently, each object must have an attribute whose value can unambiguously identify that object

If an attribute is marked as an identifier, then it is constrained to have distinct values for each instance

In xUML there are three kinds of identifier implicit identifiers single-attribute identifiers compound identifiers

Page 21: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Implicit identifier

location = rightzoom = 2

location = centrezoom = 1

location = leftzoom = 1.5

ID Location

Zoom

CAM_1 right 2

CAM_2 centre 1

CAM_3 left 1.5

Camera

ID {I}LocationZoom

Page 22: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Implicit identifier

location = rightzoom = 2

location = centrezoom = 1

location = leftzoom = 1.5

ID Location

Zoom

CAM_1 right 2

CAM_2 centre 1

CAM_3 left 1.5

Camera

ID {I}LocationZoom

But this identifieris not adding anything

to the model otherthan guaranteeing

uniqueness

Page 23: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Implicit identifier

location = rightzoom = 2

location = centrezoom = 1

location = leftzoom = 1.5

Location

Zoom

right 2

centre 1

left 1.5

Camera

LocationZoom

We can rely on animplicit identifierin this case to

guarantee uniqueness

Page 24: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Implicit vs. Explicit Identifiers

In the preceding example we were only interested in the service each camera performed in a studio We don’t actually care which precise physical

camera maps onto the class instances so long as the attribute values are correct

But sometimes we may need to model a real-world identification scheme SAO Number, Aircraft registration, Flight number

In these cases we use an explicit identifier may consist of single or multiple attributes

Page 25: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Single explicit identifier

Star

SAO Number {I}NameDiameterMassDistance

252838Alpha Centauri1.26 M km1.1 x Sun4.3 ly

131881Sirius4.9 M km3 x Sun8.7 ly

Two instances of Star

In contrast to implicit identifiers, typically thevalues of explicit identifiers will not be assigned

by the model compiler

Page 26: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Compound identifiers

State License

Number

Colour Year Make Model

CA 12345 pink 1960 Cadillac

Eldorado

CA 65432 purple 1964 AC Cobra

CO 12345 orange 1972 VW Beetle

Licensed Vehicle

State {I}License number {I}ColourMakeModel

These two attributestogether mark asingle identifier

(State + License number)

Page 27: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Referential attributes

Direction

Side Length Grade

13 Single 5000 ft Gravel

27 Left 7000 ft Paved

27 Right 7000 ft Paved

Runway

Direction {I}Side {I}LengthGrade

But we could havetwo runways with the

same value for(Direction + Side)

at different airports

Page 28: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Referential attributes

Runway

Direction {I}Side {I}Airport {I, R1}LengthGrade

Airport

Code {I}Current visibility

1

is located at

1..*

is location of

R1

Refers to identifier of theassociated Airport class(the renaming is legal)

Page 29: Executable UML The Models are the Code - Executable UML Lecture 4 - How to Build Class Models Paul Krause

Executable UML

Summary

We have illustrated some good practice in developing class models and their associated attributes

Next time we will look at the remaining properties of attributes: Dependency on other attributes Value assignment Universal meaning Origin

Read Chapter 5 of Mellor and Balcer also Chapters 1 & 2 of Starr