Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Kinds of Methods<br />
• Code Methods<br />
• Expression Methods<br />
• Call Methods<br />
• Method Generators<br />
The various method types control how the <strong>Caché</strong> class compiler interprets the Implementation<br />
of the method.<br />
6.7.1 Code Methods<br />
A code method is a method whose implementation is simply lines of code. This is the most<br />
typical type of method and is the default.<br />
For instance, the following method defines a Speak code method for the Dog class:<br />
Class MyApp.Dog Extends %Persistent [ClassType = persistent]<br />
{<br />
Method Speak() As %String<br />
{<br />
Quit "Woof, Woof"<br />
}<br />
}<br />
The method code can contain any valid <strong>Caché</strong> ObjectScript code (including embedded SQL<br />
and embedded HTML) or Basic code (depending on the method's Language keyword).<br />
Assuming dog refers to a Dog object, you could invoke this method as follows:<br />
Write dog.Speak()<br />
// yields: Woof, Woof<br />
6.7.2 Expression Methods<br />
An expression method is a method that may be replaced by the class compiler, in certain<br />
circumstances, with a direct in-line substitution of a specified expression. Expression methods<br />
are typically used for simple methods (such as those found in data type classes) that need<br />
rapid execution speed.<br />
For example, it is possible to convert the Speak method of the Dog class from the previous<br />
example into an expression method:<br />
Method Speak() As %String [CodeMode = expression]<br />
{<br />
"Woof, Woof"<br />
}<br />
Assuming dog refers to a Dog object, this method could be used as follows:<br />
<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 43