🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators assignment
This page was created by Charles on 2025-11-18. Last edited by Wikiadmin on 2026-07-29.

You use := in Executable OCL actions to assign a value to an object property or variable.

Assignment in EAL

Standard OCL is declarative and side-effect-free: an expression describes a value or constraint and does not change model data. MDriven's EAL (Executable Action Language) adds := so that an action can update a property or store a value in a variable.

Use assignment where an action is expected to change state, for example in an action, state transition, or rule.

Syntax and examples

The left-hand side (LHS) identifies the property or variable to receive a value. The right-hand side (RHS) produces the value to assign.

leftHandSide := rightHandSide

Assign an object property

This expression creates a Biocide and assigns it to the RegulatoryAffair property of the current product:

self.Product.RegulatoryAffair := Biocide.Create

Assign a variable

This expression stores the result of the division in vSomeDouble:

vSomeDouble := 44/33

Result type of an assignment

Since May 2025, an assignment expression has the type of its LHS, not the type of its RHS. This makes the result predictable when assignment is used inside another expression.

For example, 4 is an Integer literal, but SomeDouble is assumed to be a Double property:

somelist->collect(x | x.SomeDouble := 4)

The result is a collection of the type of SomeDouble, rather than a collection of Integer. MDriven permits the Integer value to be assigned to the Double property in this case.

Keep the more specific RHS type when required

The LHS type can be a superclass of the object created on the RHS. In the following example, RegulatoryAffair is a superclass of Biocide, so the assignment expression has type RegulatoryAffair:

self.Product.RegulatoryAffair := Biocide.Create

If the surrounding expression requires the created object as a Biocide, cast the assignment result:

(self.Product.RegulatoryAffair := Biocide.Create).safeCast(Biocide)

Alternatively, keep the created object in a variable and return that variable after the assignment:

let x := Biocide.Create in (
  self.Product.RegulatoryAffair := x;
  x
)

Use assignment deliberately

  • Use := only when the expression must update a property or variable.
  • Check the type expected by the receiving property or variable. Assignment allows the Integer-to-Double up-typing shown above, but the assignment expression itself still takes its type from the LHS.
  • When an assignment appears inside a larger expression, account for its LHS result type. Use safeCast or a let variable when the caller needs a more specific RHS type.

For the complete operator reference, see the := operator.

See also