Previous | Table of Contents | Next |
An operation is a behavioral feature of a classifier that specifies the name, type, parameters, and constraints for invoking
an associated behavior.
Constructs::Operation reuses the definition of Operation from Basic. It adds a specialization to Constructs::BehavioralFeature.
The specification of an operation defines what service it provides, not how this is done, and can include a list of pre- and
postconditions.
•
“BehavioralFeature? on page 149
• /isOrdered : Boolean Redefines the corresponding property from Basic to derive this information from the return result for this Operation.
• isQuery : Boolean Specifies whether an execution of the Operation leaves the state of the system unchanged (isQuery=true) or whether side effects may occur (isQuery=false). The default value is false.
• /isUnique : Boolean Redefines the corresponding property from Basic to derive this information from the return result for this Operation.
• /lower : Integer[0..1] Redefines the corresponding property from Basic to derive this information from the return result for this Operation.
• /upper : UnlimitedNatural[0..1] Redefines the corresponding property from Basic to derive this information from the return result for this Operation.
• bodyCondition: Constraint[0..1] An optional Constraint on the result values of an invocation of this Operation. Subsets Namespace.ownedRule.
• postcondition: Constraint[*] An optional set of Constraints specifying the state of the system when the Operation is completed. Subsets Namespace.ownedRule.
• precondition: Constraint[*] An optional set of Constraints on the state of the system when the Operation is invoked. Subsets Namespace.ownedRule.
• raisedException: Type[*] References the Types representing exceptions that may be raised during an invocation of this operation. Redefines Basic::Operation.raisedException and BehavioralFeature.raisedException.
• redefinedOperation: Operation[*] References the Operations that are redefined by this Operation. Subsets RedefinableElement.redefinedElement.
• /type: Type[0..1] Redefines the corresponding property from Basic to derive this information from the return result for this Operation.
[1] An operation can have at most one return parameter (i.e., an owned parameter with the direction set to ‘return’).
ownedParameter->select(par | par.direction = #return)->size() <= 1
[2] If this operation has a return parameter, isOrdered equals the value of isOrdered for that parameter. Otherwise isOrdered
is false.
isOrdered = if returnResult()->notEmpty() then returnResult()->any().isOrdered else false endif
[3] If this operation has a return parameter, isUnique equals the value of isUnique for that parameter. Otherwise isUnique
is
true.isUnique = if returnResult()->notEmpty() then returnResult()->any().isUnique else true endif
[4] If this operation has a return parameter, lower equals the value of lower for that parameter. Otherwise lower is not defined.
lower = if returnResult()->notEmpty() then returnResult()->any().lower else Set{} endif
[5] If this operation has a return parameter, upper equals the value of upper for that parameter. Otherwise upper is not defined.
upper = if returnResult()->notEmpty() then returnResult()->any().upper else Set{} endif
[6] If this operation has a return parameter, type equals the value of type for that parameter. Otherwise type is not defined.
type = if returnResult()->notEmpty() then returnResult()->any().type else Set{} endif
[7] A bodyCondition can only be specified for a query operation.
bodyCondition->notEmpty() implies isQuery
[1] The query isConsistentWith() specifies, for any two Operations in a context in which redefinition is possible, whether
redefinition would be consistent in the sense of maintaining type covariance. Other senses of consistency may be required,
for example to determine consistency in the sense of contravariance. Users may define alternative queries under names different
from 'isConsistentWith()', as for example, users may define a query named 'isContravariantWith()'.
Operation::isConsistentWith(redefinee: RedefinableElement): Boolean;
pre: redefinee.isRedefinitionContextValid(self)
isConsistentWith = (redefinee.oclIsKindOf(Operation) and
let op: Operation = redefinee.oclAsType(Operation) in
self.ownedParameter.size() = op.ownedParameter.size() and
forAll(i | op.ownedParameter[i].type.conformsTo(self.ownedParameter[i].type))
)
[2] The query returnResult() returns the set containing the return parameter of the Operation if one exists, otherwise, it
returns an empty set
Operation::returnResult() : Set(Parameter);returnResult = ownedParameter->select (par | par.direction = #return)
An operation is invoked on an instance of the classifier for which the operation is a feature. A static operation is invoked
on the classifier owning the operation, hence it can be invoked without an instance.
The preconditions for an operation define conditions that must be true when the operation is invoked. These preconditions
may be assumed by an implementation of this operation.
The postconditions for an operation define conditions that will be true when the invocation of the operation completes successfully,
assuming the preconditions were satisfied. These postconditions must be satisfied by any implementation of the operation.
The bodyCondition for an operation constrains the return result. The bodyCondition differs from postconditions in that the
bodyCondition may be overridden when an operation is redefined, whereas postconditions can only be added during redefinition.
An operation may raise an exception during its invocation. When an exception is raised, it should not be assumed that the
postconditions or bodyCondition of the operation are satisfied.
An operation may be redefined in a specialization of the featured classifier. This redefinition may specialize the types of
the formal parameters or return results, add new preconditions or postconditions, add new raised exceptions, or otherwise
refine the specification of the operation.
Each operation states whether or not its application will modify the state of the instance or any other element in the model
(isQuery).
The behavior of an invocation of an operation when a precondition is not satisfied is a semantic variation point.
When operations are redefined in a specialization, rules regarding invariance, covariance, or contravariance of types and
preconditions determine whether the specialized classifier is substitutable for its more general parent. Such rules constitute
semantic variation points with respect to redefinition of operations.
An operation is shown as a text string of the form:
[<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’ [‘:’ [<return-type>] ‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]
where:
• <visibility> is the visibility of the operation (See “VisibilityKind? on page 88.) <visibility> ::= ‘+’ | ‘-‘
• <name> is the name of the operation.
• <return-type> is the type of the return result parameter if the operation has one defined.
• <oper-property> indicates the properties of the operation
<oper-property> ::= ‘redefines’ <oper-name> | ‘query’ | ‘ordered’ | ‘unique’ | <oper-constraint>
where:
• redefines <oper-name> means that the operation redefines an inherited operation identified by <oper-name>.
• query means that the operation does not change the state of the system.• ordered means that the values of the return parameter are ordered.
• unique means that the values returned by the parameter have no duplicates.
• <oper-constraint> is a constraint that applies to the operation.
• <parameter-list> is a list of parameters of the operation in the following format:<parameter-list> ::= <parameter> [‘,’<parameter>]*<parameter> ::= [<direction>] <parameter-name> ‘:’ <type-expression>
[‘[‘<multiplicity>’]’] [‘=’ <default>] [‘{‘ <parm-property> [‘,’ <parm-property>]* ‘}’]
where:
• <direction> ::= ‘in’ | ‘out’ | ‘inout’ (defaults to ‘in’ if omitted).
• <parameter-name> is the name of the parameter.
• <type-expression> is an expression that specifies the type of the parameter.
• <multiplicity> is the multiplicity of the parameter. (See “MultiplicityElement? on page 64.)
• <default> is an expression that defines the value specification for the default value of the parameter.
• <parm-property> indicates additional property values that apply to the parameter.
The parameter list can be suppressed. The return result of the operation can be expressed as a return parameter, or as the
type of the operation. For example:
toString(return : String)
means the same thing as
toString() : String
An operation name typically begins with a lowercase letter.
display ()
-hide ()
+createWindow (location: Coordinates, container: Container [0..1]): Window
+toString (): String