Information Technology Reference
In-Depth Information
context LoyaltyAccount::transactions : Set(Transaction)
init: Set{}
Note the difference between an initial value and a derivation rule. A derivation
rule states an invariant: The derived element should always have the same value
that the rule expresses. An initial value, however, must hold only at the moment
when the contextual instance is created. After that moment, the attribute may have
a different value at any point in time.
8.5.2.10 Body of Query Operations
The class diagram can introduce a number of query operations. Query operations
are operations that have no side effects, i.e., do not change the state of any instance
in the system. Execution of a query operation results in a value or set of values,
without any alterations in the state of the system. Query operations can be intro-
duced in the class diagram, but can only be fully defined by specifying the result of
the operation. Using OCL, the result can be given in a single expression, called a
body expression. In fact, OCL is a full query language, comparable to SQL. The
use of body expressions is an illustration thereof.
The next example states that the operation getCustomerName will always result
in the name of the card owner associated with the loyalty account:
context LoyaltyAccount::getCustomerName() : String
body: Membership.card.owner.name
8.5.2.11 Broken constraints
Note that evaluating a constraint does not change any values in the system. A
constraint states ''this should be so''. If for a certain object the constraint is not
true, in other words, it is broken, the only thing we can conclude is that the object
is not correct, and it does not conform to our specification. Whether this is a fatal
error or a minor mistake, what should be done to correct the situation is not
expressed in the OCL (Introduction to OCL 2005 ).
8.5.3 OCL Collections
Local attribute: The constraint involves an attribute that is local to the class of
interest.
Directly related class: The expression involves the navigation of a single
association to a directly related class.
Search WWH ::




Custom Search