Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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 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 R1 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 R1 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 R1 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..* R1 Ticket number {I} Airline {I, R1} Cost Class Seat assignment Executable UML 0..* Role Classes 0..* R1 0..1 Wafer Inspection Station contains is loaded into Wafer in Process Inspection Script 0..1 Allignment directs Temperature Percent scan complete scanning of Delete once Wafer has been unloaded from the Inspection Station Executable UML R2 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 3D space and must 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; 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? 1 R1 1..* Flat Shape Side can be shown by Executable UML can show Colour Texture Two 1:1 associations? 1 Flat Shape R1 is front of 1 is back of 1 has front R2 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 R1 is front of 1 is back of 1 has front R2 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 R1 is front of 0..1 is back of 1 has front R2 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 R1 is front of 0..1 is back of 1 has front R2 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 R1 1 Bitmap Image has drawn R4 Front Side Back Side has on front 1 has on back 1 R2 is front of 1 R3 is back of 1 Flat Shape Executable UML 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 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 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 ID Using “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 = 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 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 Two instances of Star 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 R1 Direction {I} is located at is location of Side {I} Airport {I, R1} Length Grade Refers to identifier of the associated Airport class (the renaming is legal) Executable UML 1..* 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 Executable UML