25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

##this Syntax<br />

>Do ##class(Package.Class1)Class2Instance.Method(Args)<br />

>Set localname = ##class(Package.Class1)Class2Instance.Method(Args)<br />

You can cast both class methods and instance methods.<br />

For example, suppose that two classes, MyClass.Up and MyClass.Down, both have Go methods.<br />

The code of MyClass.Up.Go is:<br />

Method Go()<br />

{<br />

Write "Go up.",!<br />

}<br />

and the code of MyClass.Down.Go is:<br />

Method Go()<br />

{<br />

Write "Go down.",!<br />

}<br />

You can then create an instance of MyClass.Up and use it to invoke the MyClass.Down.Go<br />

method:<br />

>Set LocalInstance = ##class(MyClass.Up).%New()<br />

>Do ##class(MyClass.Down)LocalInstance.Go()<br />

Go down.<br />

It is also valid to use ##class as part of an expression, as in<br />

Write ##class(Class).Method(args)*2<br />

without setting a variable equal to the return value.<br />

A more generic way to refer to other methods are the $ZObjMethod and $ZObjClassMethod<br />

functions, which are for instance and class methods, respectively. These provide a mechanism<br />

for referring to packages, classes, and methods programmatically.<br />

21.3 ##this Syntax<br />

The ##this syntax provides a handle to the OREF of the current instance, such as for passing<br />

it to another class or for another class to refer to the current instance's members. When an<br />

instance refers to its own members, the .. syntax is preferred.<br />

Note:<br />

##this is case sensitive and must be in all lowercase.<br />

<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 181

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!