8.3 Referential Constraints


When we begin abstracting classes and attributes, our candidate classes might include attributes such as

  • Book.publisher

  • CreditCardCharge.accountNumber

  • Order.customerID

Attributes like these are characteristics of the classes, but they also refer to the related classes. It is important, then, that we capture the fact that each such attribute is tied to an association.

8.3.1 Referential Attributes

A 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 {Rn}, where n is the number of the association being formalized. For example, the attribute BookProduct.publisher refers to the identifier of Publisher, formalizing the association named R1. See Figure 8.10.

Figure 8.10. Referential Attributes

graphics/08fig10.gif

Once there is a referential attribute formalizing the association, there is no need to put in a "backwards pointer" in Publisher. That would be redundant, because it formalizes the same fact about R1. (Model compilers can optimize the actual storage scheme for the association based on the pattern of usage of access, not on the placement of the referential attribute.)

Names of referential attributes.

There is no requirement that the name of the referential attribute be exactly the same as the identifying attribute of the referred-to class, only that the set of values the referential attribute can take on is the same as a currently existing value for the identifying attribute.

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 Loops.

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 meant inventing identifiers. This practice is not required in Executable UML.

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 group (a national or regional collection of publishers), those in the second set identify the publisher, and the remaining characters identify the book.[1]

[1] Actually, the last character is a check digit, but we'll consider that to be part of the book code.

This string actually comprises three pieces of information:

  • the group code

  • the publisher code

  • the title code

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)

graphics/08fig11.gif

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

graphics/08fig12.gif

Figure 8.13. Action Language Definition of Derived Attribute bookISBN

graphics/08fig13.gif

Definition: A derived identifier 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.

Compound Identifiers

An identifier can be constructed as a multi-attribute identifier using referential attributes. Shlaer-Mellor required compound identifiers as solutions to the book ISBN problem above. Figure 8.14 shows a Shipment with a two-attribute compound identifier.

Figure 8.14. Compound Identifier Using Referential Attributes

graphics/08fig14.gif

The compound identifier also provides a solution for formalizing constraints on association loops. See the box "Loop Constraints with Combined Referential Attributes" on page 144.

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.



Executable UML. A Foundation for Model-Driven Architecture
Executable UML: A Foundation for Model-Driven Architecture
ISBN: 0201748045
EAN: 2147483647
Year: 2001
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net