The set of values an attribute can take on constitutes its data type. Each attribute must have a data type. Tools today capture this information through dialog screens and in some cases by data type definition as a part of the action language. Since there is no compact standard way to capture all this information, we shall use an informal textual notation. Data types in Executable UML are based on a two-level scheme:
Each data type has a domain-specific name, used on the class diagram, and a definition: the formal, detailed part. 5.3.1 Core Data TypesDefinition: A core data type is a fundamental datatype from which other domain-specific datatypes can be defined. Core data types include boolean, string, integer, real, date, and timestamp. We summarize these in Figure 5.3 overleaf. Figure 5.3. Core Data Types5.3.2 Domain-Specific Data TypesWhile attributes may be defined in terms of core data types, by defining attributes in terms of individual domain-specific data types, the developer can specify precisely the values that are legal for an attribute and can identify those attributes that can take on the same kinds of values. Definition: A domain-specific data type is a definition of the set of legal values that can be assigned to attributes in a domain model. Domain-specific data types can represent subsets of values of the core data type (for example, a range of positive integers). In addition, domain-specific data types can be defined to represent symbolic enumerations and composite values. In all cases, the assignment of domain-specific data types to actual implementation data types is handled by the model compiler, based on the specific performance properties supported by that model compiler. Numeric types.Domain-specific numeric types provide for values that have units, range, and precision. The data type Currency may be defined, in keeping with the example above:
which specifies that Currency is of type numeric, with a range from 0 to 100000, with a precision of 0.01. String types.String types provide for values that contain textual data. These can be specified in terms of a size and a pattern.
Enumerated types.Enumerated types are described by a list of values.
Composite values.A type may be composite, but the corresponding attribute must always be treated by the domain as a single unit. For example, MailingAddress and TelephoneNumber are valid types, but no operations in the domain can access the city as a part of the mailing address, nor an area code as a part of the telephone number. (Another domain, on the other hand, may choose to treat these attributes as objects, and their components as separate attributes.) 5.3.3 Using TypesEach attribute has a type. These are shown in the class definition (and the class diagram as in Figure 5.4) as the attribute name, type, and an optional initial value. Figure 5.4. Class Box with All ComponentsHence, for a class Customer
specifies that the attribute Customer.purchasesMade has a type, Count, and asserts an initial (default) value of zero. Syntax vs. semantics.Define attribute types in terms of the meaning of the data (the semantics), not merely in the form of the data. Good models should use domain-specific types as much as possible and refrain from using the core data types if more meaning is available. Hence, defining an attribute merely as real is not as good as using a domain-specific type, such as Currency or SupplyVoltage. |