8.2 Derived Attributes
Because an Executable UML model captures the information inherent in a domain, redundant attributes are
Definition: A derived attribute is an attribute whose value can be computed from other attributes already in the model. Figure 8.9 shows two derived attributes, each prefixed by a / (slash). Figure 8.9. Derived Attributes
The attribute ProductSelection.selectionValue can be defined in OCL like this:
or in action language this way:
Executable UML enforces this constraint by prohibiting writing to the attribute totalSelectionPrice and by requiring any model compiler to guarantee the constraint before the attribute can be read. Derived attribute dependencies can span multiple classes. Figure 8.9 also shows how the class Order allows a customer to purchase several different products in one transaction. Each product is represented as a distinct ProductSelection. In this example, Order.totalOrderAmount is derived from the sum of all the associated ProductSelection.totalSelectionPrice. Its definition in OCL looks like this:
This derived attribute definition is written in action language, as shown below.
Unlike the identifier idiom, which can be represented by tags, the derived attribute marker (/) indicates the presence of a constraint that must be specified.
|
8.3 Referential Constraints
When we begin
Attributes like these are characteristics of the classes, but they also refer to the
8.3.1 Referential AttributesA referential attribute identifies the instance of the associated class. Definition: A referential attribute is an attribute whose value is the value of an identifying attribute in one or more associated classes.
We tag the referential attribute with {R
n
}, where
n
is the number of the association being
Figure 8.10. Referential Attributes
Once there is a referential attribute formalizing the association, there is no need to put in a "
Names of referential attributes.
There is no requirement that the
When a class is identified by multiple attributes, an association is formalized using all of the identifier's attributes, though there are some exceptions described in Section 8.4: Association
Referential attributes not mandatory.For the purposes of knowledge formalization, the existence of the association and its description is sufficient to communicate meaning.
Shlaer-Mellor required referential attributes for all associations, even if it
However, referential attributes are useful in cases where it is easier to express constraints and selection expressions in terms of data (attributes) than associations. The following sections provide some examples of these uses of referential attributes. 8.3.2 Derived Identifiers
A book's ISBN ("International Standard Book Number") is a ten-character string. The first set of characters identify a publication
This string actually comprises three pieces of information:
The title code itself does not uniquely identify a book across the entire population of books of all publishers in all languages. By itself, it is not an identifier for a book. Rather, the identifier is the concatenation of all three attributes. A multi-attribute identifier is one solution, but given that the domain experts will consistently refer to the ISBN and that selecting instances of books by three attributes is rather messy, we should really make the ISBN of Figure 8.11 into a single attribute identifier. Figure 8.11. Components of an International Standard Book Number (ISBN)
In Figure 8.12, we represent the ISBN number as a derived attribute, based on the publication group, publisher, and title code, and Figure 8.13 shows the definition of the attribute. Figure 8.12. Derived Identifier
Figure 8.13. Action Language Definition of Derived Attribute bookISBN
Definition: A derived identi fi e r is an identifier that is the derived concatenation of several identifying attributes. Derived identifiers are commonly used in situations where an attribute is unique within a subset of instances and all the instances in the subset are related to a single instance. In this case, the attribute Book.bookNumber must be unique for all books published by a given publisher in a given language. Two publishers (who have distinct publisherCodes) may each publish a book with the same bookNumber. The bookNumber by itself does not uniquely identify a BookProduct, but the combination of language, publisher, and bookNumber does uniquely identify a BookProduct.
We may then refer to this derived identifier in constraints, referential attributes, and action language. Note that this attribute is both derived and an identifier because no two instances could have the same value. |