The Models are the Code Executable UML Lecture
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 v Specifications vs Things v Interactions v Roles v working within our modelling goals v Attributes Executable UML
Specification Classes Abstract Aircraft Specification Model number {I} Stall profile Weight Wingspan Fuel consumption Properties common to a specific aircraft type Executable UML Concrete Distinct lifecycles and properties 1 design is specified by R 1 Aircraft Registration number {I} Maintenance status specifies Assigned pilot design of Assigned mechanic Hours flown 0. . * Properties common to a specific aircraft instance
Specification Pattern Will rarely need a state model to define its behaviour Will normally need a state model to define its behaviour Abstract Widget Specification Model number {I} Concrete 1 design is specified by design characteristics, references to sub-specifications or other related specifications Executable UML R 1 0. . * specifies design of Widget Serial number {I} characteristics that vary from widget to widget, even when the widgets are defined by the same widget specification
Interaction Classes Flight Passenger 0. . * Name Phone number R 1 is reserved for ? ? Seat Assignment Executable UML Number {I} Airline {I} reserves Departure date Departure time Departure airport Arrival date Arrival time ? ? Arrival airport 0. . *
Interaction Classes Flight Passenger Name Phone number Number {I} Airline {I} is reserved reserves Departure date Departure time for Departure airport Arrival date Arrival time Reservation Arrival airport 0. . * R 1 Ticket number {I} Airline {I, R 1} Cost Class Seat assignment Executable UML 0. . *
Role Classes 0. . * Wafer R 1 contains 0. . 1 Inspection Station is loaded into Wafer in Process 0. . 1 Allignment directs Temperature Percent scan complete scanning of Delete once Wafer has been unloaded from the Inspection Station Executable UML R 2 Inspection Script 0. . 1 Area to cover is scanned Scan method according to
Relative Roles Back Side Front Side APPLICATION NOTE: The flat shape can rotate in 3 D space and must have exactly one bitmap image on each of its two sides Executable UML
Multiplicity v Remember, an important characteristic of an association is the number of instances (objects) that participate in each instance of the domain relationship v UML allows specific numbers in a multiplicity relation v In x. UML the recommendation is to only use four kinds: v unconditional; v conditional; Executable UML 1, or 1. . * 0. . 1, or 0. . *
Relative Roles The arguments for making this multiplicity “ 2” seem compelling, but can we work within our modelling guidelines? Flat Shape 1 can be shown by Executable UML R 1 1. . * Side can show Colour Texture
Two 1: 1 associations? 1 Flat Shape R 1 is front of 1 is back of 1 has front R 2 1 Side Colour Texture has back But a Side is either the Front or the Back of a Flat Shape, not both! Executable UML
Two 1: 1 associations? 1 Flat Shape R 1 is front of 1 is back of 1 has front R 2 1 Side Colour Texture has back But a Side is either the Front or the Back of a Flat Shape, not both! Executable UML
Two conditional associations? 0. . 1 Flat Shape R 1 is front of 0. . 1 is back of 1 has front R 2 1 Side Colour Texture has back But this says that a Side might exist that does not belong to any Flat Shape! Executable UML
Two conditional associations? 0. . 1 Flat Shape R 1 is front of 0. . 1 is back of 1 has front R 2 1 Side Colour Texture has back 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 colour Front texture Back colour Back texture ? Bitmap Image But we need to model the association between a Bitmap Image and a specific Side! Executable UML
Solution: Abstract Positional roles as Classes Side 0. . * Colour Texture is drawn on R 4 Front Side Back Side has on front 1 has on back 1 R 2 is front of 1 R 3 is back of 1 Flat Shape Executable UML R 1 1 Bitmap Image has drawn N. B. We have worked within our modelling goals and produced a better model!
What is an Attribute? “A quality or characteristic inherent in or ascribed to someone or something” The American Heritage Dictionary of the English Language Two instances of Star SAO Number {I} Name Diameter Mass Distance Attributes: Prototypical characteristics Executable UML 252838 Alpha Centauri 1. 26 M km 1. 1 x Sun 4. 3 ly 131881 Sirius 4. 9 M km 3 x Sun 8. 7 ly Attribute Values: Characteristics of a specific instance
Properties of Attributes v Purpose v Identification role v Dependency on other attributes v Value assignment v Universal meaning Executable UML
Purpose v Here the attribute either names or describes a class instance v Descriptive attributes v Size, Capacity, Colour, Stall speed v Naming attributes v Discovered names - Company name, Floor number, Driver’s licence number v Invented names - Pump ID, Transaction ID, Event ID w Using “ID” as a suffix makes it clear these names are the invention of an analyst Executable UML
Identification role v Every instance of a class is unique v Consequently, each object must have an attribute whose value can unambiguously identify that object v If an attribute is marked as an identifier, then it is constrained to have distinct values for each instance v In x. UML there are three kinds of identifier v implicit identifiers v single-attribute identifiers v compound identifiers Executable UML
Implicit identifier location = right zoom = 2 location = centre zoom = 1 location = left zoom = 1. 5 Executable UML ID Location Zoom CAM_1 right 2 CAM_2 centre 1 CAM_3 left 1. 5 Camera ID {I} Location Zoom
Implicit identifier location = right zoom = 2 ID Location Zoom CAM_1 right 2 CAM_2 centre 1 CAM_3 left 1. 5 location = centre zoom = 1 But this identifier is not adding anything location = left to the model other zoom = 1. 5 than guaranteeing uniqueness Executable UML Camera ID {I} Location Zoom
Implicit identifier location = right zoom = 2 Location Zoom right 2 centre 1 left 1. 5 location = centre zoom = 1 We can rely on an implicit identifier location = left in this case to zoom = 1. 5 guarantee uniqueness Executable UML Camera Location Zoom
Implicit vs. Explicit Identifiers v In the preceding example we were only interested in the service each camera performed in a studio v We don’t actually care which precise physical camera maps onto the class instances so long as the attribute values are correct v But sometimes we may need to model a real- world identification scheme v SAO Number, Aircraft registration, Flight number v In these cases we use an explicit identifier v may consist of single or multiple attributes Executable UML
Single explicit identifier Two instances of Star SAO Number {I} Name Diameter Mass Distance 252838 Alpha Centauri 1. 26 M km 1. 1 x Sun 4. 3 ly In contrast to implicit identifiers, typically the values of explicit identifiers will not be assigned by the model compiler Executable UML 131881 Sirius 4. 9 M km 3 x Sun 8. 7 ly
Compound identifiers State License Colour Year Make Model Number 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} Colour Make Model Executable UML These two attributes together mark a single identifier (State + License number)
Referential attributes Runway Direction {I} Side {I} Length Grade Direction Side Length Grade 13 Single 5000 ft Gravel 27 Left 7000 ft Paved 27 Right 7000 ft Paved But we could have two runways with the same value for (Direction + Side) at different airports Executable UML
Referential attributes Airport Runway Code {I} Current visibility 1 R 1 Direction {I} is located at is location of Side {I} Airport {I, R 1} Length Grade Refers to identifier of the associated Airport class (the renaming is legal) Executable UML 1. . *
Summary v We have illustrated some good practice in developing class models and their associated attributes v Next time we will look at the remaining properties of attributes: v Dependency on other attributes v Value assignment v Universal meaning v Origin v Read Chapter 5 of Mellor and Balcer v also Chapters 1 & 2 of Starr Executable UML
- Slides: 29