7.2 Selection Expressions


Actions can operate on one or more objects in the domain. We use selection expressions to select single objects or sets of objects. The result of a selection expression is an object reference set.

Definition: An object reference set holds a set of object references.

The extent of a class is its current set of objects. (A set is a mathematical term that means some number (possibly zero) of distinct elements. A class extent is always a set because the objects of a class are defined to be distinct.)

Figure 7.3 shows actions and concepts related to object selection, and several examples are shown in Figure 7.4. The first statement gets the extent of all books, and the object reference set books refers to the current set of books.

Figure 7.3. Selection Expressions

graphics/07fig03.gif

Figure 7.4. Examples of Selection Expressions and Adjuncts

graphics/07fig04.gif

To access a subset of the objects in an extent, we specify the criteria that define the subset using a where clause in which selected refers to the current object, and the dot operator accesses attributes of that object. The second statement in Figure 7.4 returns the subset of all books copyrighted in 2002.

The selection expression may be an arbitrarily complex expression written in terms of the attributes of the class, as shown in the third statement.

A select statement may fail to find any objects. The operator empty, applied to an object reference, is true if the (object reference) set is empty, and the select statement did not find any objects. The last two statements select reallyNewBooks and check whether the object reference set is empty.

When we have a set of objects, we can operate on each instance of that set, as illustrated in Figure 7.5.

Figure 7.5. Example of Iteration

graphics/07fig05.gif

All the select statements above return many instances by design, as indicated by the many operator.

To return a single, arbitrary, instance, use any, as illustrated in Figure 7.6. The example picks a single publisher from the many that qualify. The any operator assumes that many publishers are huge, but returns only one.

Figure 7.6. Examples of Selection Expressions and Adjuncts

graphics/07fig06.gif



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