Previous Table of Contents Next


11.8.2 Operation


   An operation is a behavioral feature of a classifier that specifies the name, type, parameters, and constraints for invoking an associated behavior.

Description

   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.

Generalizations

   • “BehavioralFeature? on page 149

Attributes Associations Constraints

   [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

Additional Operations

   [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)

Semantics

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

Semantic Variation Points

   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.

Notation

   An operation is shown as a text string of the form:

   [<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’ [‘:’ [<return-type>] ‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]

   where:

   <oper-property> ::= ‘redefines’ <oper-name> | ‘query’ | ‘ordered’ | ‘unique’ | <oper-constraint>

   where:

   • <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:

Presentation Options

   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

Style Guidelines

   An operation name typically begins with a lowercase letter.

Examples

   display ()

   -hide ()

   +createWindow (location: Coordinates, container: Container [0..1]): Window

   +toString (): String