executable uml the models are the code - executable uml lecture 4 - how to build class models paul...
TRANSCRIPT
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
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
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
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
????
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
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
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
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..*
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?
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!
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!
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!
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!
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!
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!
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
Executable UML
Properties of Attributes
Purpose
Identification role
Dependency on other attributes
Value assignment
Universal meaning
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
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
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
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
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
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
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
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)
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
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)
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