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.
Methods<br />
6.6 Instance and Class Methods<br />
Generally, the term “method” refers to an instance method, which is a method that is invoked<br />
from a specific instance of a class that performs some action related to that instance, such as<br />
performing business logic, displaying information about the instance, and so on. For example,<br />
suppose you have an instance of the Sample.Person class (included in the “Samples”<br />
namespace) in memory called MyPerson; you can then invoke its instance methods, such as<br />
its NinetyNine method (a example method that simply returns the value 99):<br />
Set x = MyPerson.NinetyNine()<br />
This line of code uses the NinetyNine method to set x equal to 99.<br />
In addition to instance methods, <strong>Caché</strong> supports class methods. A class method is not necessarily<br />
associated with a particular object and need not be invoked from an open object. As<br />
such, you can invoke a class method in either of two ways:<br />
• Without any object reference<br />
• From a specific instance in order to act on one or more objects of the class<br />
A class method can refer to other class methods, but cannot refer to any object properties or<br />
instance methods. For example:<br />
Set x = ##class(Invoice).%Open(oid)<br />
Set x = ##class(Patient).%New()<br />
The first example involves the %Open class method of the Invoice class, which takes the<br />
OID of a particular instance, opens that instance, and returns a handle to it; the second<br />
example uses the Patient class' the %New method to create a new Patient instance and return<br />
a handle to it.<br />
Class methods are important because you can invoke them without having an instance that<br />
is already open. For example, you can use the %New and %OpenId class methods to create<br />
or open an instance. Class methods are also useful for actions that involve multiple or all<br />
instances of a class.<br />
6.7 Kinds of Methods<br />
<strong>Caché</strong> supports four types of methods:<br />
42 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>