Skip to main content

Types of Methods (CodeMode Options)

Types of Methods (CodeMode Options)

InterSystems IRIS supports four types of methods, which the class compiler handles differently:

Code Methods

A code method is a method whose implementation is simply lines of code. This is the most typical type of method and is the default.

The method implementation can contain any code that is valid for the implementation language.

Note:

InterSystems IRIS comes with a set of system-defined methods that perform simple, common tasks. If a user-defined method performs one of these tasks, then the compiler does not generate any executable code for it. Rather, it associates the user-defined method with the system-defined method, so that invoking the user-defined method results in a call to the system-defined method, with an associated performance benefit. Also, the debugger does not step through such a system-defined method.

Expression Methods

An expression method is a method whose implementation consists of only an expression. When executed, the method returns the value of that expression. Expression methods are typically used for simple methods (such as those found in data type classes) that need rapid execution speed.

For example, it is possible to convert the Speak() method of the Dog class from the previous example into an expression method:

Method Speak() As %String [CodeMode = expression]
{
    "Woof, Woof"
}

Assuming dog refers to a Dog object, this method could be used as follows:

   Write dog.Speak()

Which could result in the following code being generated:

   Write "Woof, Woof"

It is a good idea to give default values to all formal variables of an expression method. This prevents potential substitution problems caused by missing actual variables at runtime.

Note:

InterSystems IRIS does not allow macros or call-by-reference arguments within expression methods.

Call Methods

A call method is a special mechanism to create method wrappers around existing InterSystems IRIS routines. This is typically useful when migrating legacy code to object-based applications.

Defining a method as a call method indicates that a specified routine is called whenever the method is invoked. The syntax for a call method is:

Method Call() [ CodeMode = call ]
{
    Tag^Routine
}

where Tag^Routine specifies a tag name within a routine.

Method Generators

A method generator is actually a small program that is invoked by the class compiler during class compilation. Its output is the actual runtime implementation of the method. Method generators provide a means of inheriting methods that can produce high performance, specialized code that is customized to the needs of the inheriting class or property. Within the InterSystems IRIS library, method generators are used extensively by the data type and storage classes.

For details, see Defining Method and Trigger Generators.

FeedbackOpens in a new tab