Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Object-Specific ObjectScript Features<br />
For example, suppose there is an application with an Accounting.Order class and an<br />
Accounting.Utils class. The Accounting.Order.CalcTax method calls the<br />
Accounting.Utils.GetTaxRate and Accounting.Utils.GetTaxableSubtotal methods, passing the<br />
current instance's city and state values to GetTaxRate and passing the list of items ordered<br />
and relevant tax-related information to GetTaxableSubtotal. CalcTax then uses the values<br />
returned to calculate the sales tax for the order. Hence, its code is something like:<br />
Method CalcTax() As %Numeric<br />
{<br />
Set TaxRate = ##Class(Accounting.Utils).GetTaxRate(##this)<br />
Write "The tax rate for ",..City,", ",..State," is ",TaxRate*100,"%",!<br />
Set TaxableSubtotal = ##class(Accounting.Utils).GetTaxableSubTotal(##this)<br />
Write "The taxable subtotal for this order is $",TaxableSubtotal,!<br />
Set Tax = TaxableSubtotal * TaxRate<br />
Write "The tax for this order is $",Tax,!<br />
}<br />
The first line of the method uses the ##Class syntax (described above) to invoke the other<br />
class' method; it passes the current object to that method using the ##this syntax. The second<br />
line of the method uses the .. syntax (also described above) to get the values of the instance's<br />
City and State properties. The action on the third line is similar to that on the first line.<br />
The Accounting.Utils class' GetTaxRate method can then use the handle to the passed-in<br />
instance to get handles to various properties — for both getting and setting their values:<br />
ClassMethod GetTaxRate(OrderBeingProcessed As Accounting.CustOrder) As %Numeric<br />
{<br />
Set LocalCity = OrderBeingProcessed.City<br />
Set LocalState = OrderBeingProcessed.State<br />
// code to determine tax rate based on location and set<br />
// the value of OrderBeingProcessed.TaxRate accordingly<br />
Quit OrderBeingProcessed.TaxRate<br />
}<br />
The GetTaxableSubtotal method also uses the handle to the instance to look at its properties<br />
and set the value of its TaxableSubtotal property.<br />
Hence, the output at the <strong>Caché</strong> terminal from invoking the CalcTax method for MyOrder<br />
instance of the Accounting.Order class would be something like:<br />
>Do MyOrder.CalcTax()<br />
The tax rate for Cambridge, MA is 5%<br />
The taxable subtotal for this order is $79.82<br />
The tax for this order is $3.99<br />
182 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>