🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLEditorHelp OclPreconditionQuery
This page was created by Hans.karlsen on 2021-12-31. Last edited by Wikiadmin on 2026-07-29.

You can test whether a method's defined precondition is currently met by calling its automatically created PreconditionQuery; this is for modelers writing OCL expressions around MDriven methods.

What PreconditionQuery does

A method can have a precondition: a rule that must be met before you execute that method. For every method with a precondition, MDriven creates a corresponding query operator that lets you evaluate that rule without executing the method.

The query operator has the method name followed by a question mark:

self.MethodName?

For example, if a class has a method named SomeMethod, use the following expression to check its precondition:

self.SomeMethod?

Use the generated query

  1. Define the precondition for the method.
  2. Refer to the method from an OCL expression on an instance of the class.
  3. Append ? to the method name to evaluate the method's precondition.

For a method named Approve, the precondition query is:

self.Approve?

Use the query when you need to determine whether the method may be executed. The query checks the precondition; it does not execute the method.

Naming rule

Method name Generated precondition query
SomeMethod self.SomeMethod?
Approve self.Approve?

OCL and actions

OCL is used for expressions and queries and must not have side effects. When you need to change data, use EAL (Extended Action Language), which uses OCL-like syntax for actions. Use a precondition query to test the rule before an action invokes the method.

See also