Previous UML Classes Table of Contents UML Packages Next


7.3.36 Operation

Kernel , Interfaces


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

*Generalizations

   

    BehavioralFeature (from Kernel ) on page 47

*Description

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

*Attributes

*Associations

   • class : Class [0..1] The class that owns this operation. Subsets RedefinableElement ::redefinitionContext, NamedElement ::namespace and Feature::featuringClassifier

   • bodyCondition: Constraint[0..1] An optional Constraint on the result values of an invocation of this Operation. Subsets Namespace ::ownedRule

Issue Editorial change: make ‘ownedParameter’ ordered

   • ownedParameter: Parameter[*] {ordered} Specifies the parameters owned by this Operation. Redefines BehavioralFeature::ownedParameter.

   RedefinableElement ::redefinedElement

   • /type: Type[0..1] Specifies the return result of the operation, if present. This is a derived value.

   Package Interfaces

   • interface: Interface [0..1] The Interface that owns this Operation. (Subsets RedefinableElement ::redefinitionContext, NamedElement ::namespace and Feature::featuringClassifier)

*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 logically consistent. A redefining operation is consistent with a redefined operation if it has the same number of owned parameters, and the type of each owned parameter conforms to the type of the corresponding redefined parameter.

   A redefining operation is consistent with a redefined operation if it has the same number of formal parameters, the same

   number of return results, and the type of each formal parameter and return result conforms to the type of the

   corresponding redefined parameter or return result.

   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.

   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 owned parameters, 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).

   An operation may be owned by and in the namespace of a class that provides the context for its possible redefinition.

*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

Issue 8298 -add qualifying phrase in front 8228 -add brackets to BNF

   If shown in a diagram, 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 (from Kernel ) on page 141).

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

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

*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