6.5 Expressions in Behavior Diagrams


This section explains the way in which expressions may be used in UML behavior diagrams. The model elements that may be used in an expression in a behavior diagram are all attributes, query operations, states, and associations of the contextual type. What the contextual type is depends on the position of the expression in the diagram, as explained in the following sections.

6.5.1 Instances

An interaction diagram shows the lifelines of instances. In an activity diagram, a number of activities may be executed by a specific instance. To indicate which instances are depicted and their mutual relationships, OCL expressions can be used. The context of these expressions is the diagram in which they occur. The contextual instance can be any instance in the system. Note that it is good practice to state the contextual instance explicitly. The contextual type is the type of the contextual instance.

6.5.2 Conditions

A message in a sequence or collaboration diagram can have an attached condition that specifies in what circumstances the message is sent. This condition can be written as an OCL expression. In this case, the OCL expression is linked to an instance, not to a type. The contextual instance is the instance that sends the message, the source. The context is the message. The contextual type is the type of the contextual instance.

Conditions may also be part of activity diagrams. In this case, the contextual instance is the instance that executes the overall activity, as specified by the complete diagram. The context is the decision node. The contextual type is the type of the contextual instance.

6.5.3 Guards

OCL expressions can be used to express guards in statecharts. The context is the transition for which the guard is defined. A guard is included in the statechart diagram itself. It is written between square brackets ([ and ]) before the event coupled to a transition. The contextual type for a guard is the type to which the statechart belongs. The contextual instance is the instance of the contextual type for which a transition fires.

6.5.4 Actual Parameter Values

Messages in collaboration and sequence diagrams can take parameters. Because a message represents an operation call these parameters are actual values. You can specify the actual value of such a parameter using an OCL expression. The context of the expression is the message. The contextual instance is the instance that sends the message. The contextual type is the type of the contextual instance.

Note that a message to an object in an interaction diagram must conform to an operation in the type of the target object, or to a signal that has been elsewhere defined. Likewise, the result message in an interaction diagram must conform to the type indicated as the result type of the called operation.

Actions in statechart or activity diagrams can take parameters too. Like the parameters to messages in an interaction diagram, these are actual values that can be specified using an OCL expression. The context of the expression is the action. Note that the parameter values must conform to the operation called, or the signal sent. As with guards, the contextual type is the type to which the statechart belongs, and the contextual instance is the instance of the contextual type that executes the action.

6.5.5 Target to Actions or Activities

An action in a statechart represents either an operation call or the sending of an event. An action is targeted at a specific object or set of objects. An OCL expression can be used to identify the target of an action. Actions may be linked to either transitions or states in a statechart. The context of the expression is the transition or state to which the action is linked. The contextual instance is the instance that executes the transition.

An activity in an activity diagram may also represent an operation call. The target of this call can be specified by an OCL expression, in a similar fashion to the targets in a statechart. The context in this case is the activity. The contextual instance is the instance that executes the overall activity, as specified by the complete diagram. In both diagrams, the contextual type is the type of the contextual instance.

6.5.6 Change Events

A change event is generated when one or more attributes or associations change value according to an expression. The event occurs whenever the value of the expression changes from false to true. A change event is denoted in the statechart by the keyword when , followed by the expression.

The condition of the change event can be written in OCL. The context of the expression is the transition. As with guards, the contextual type is the type to which the statechart belongs.



Object Constraint Language, The. Getting Your Models Ready for MDA
The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)
ISBN: 0321179366
EAN: 2147483647
Year: 2003
Pages: 137

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