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.
Dynamic Dispatch<br />
22.2 Content of Methods Implementing Dynamic<br />
Dispatch<br />
As the application developer, you have control over the content of dispatch methods. The<br />
code within them can be whatever is required to implement the methods or properties that<br />
the class is attempting to resolve.<br />
Code for dynamic dispatch might include attempts to locate a method based on other classes<br />
in the same extent, package, database, on the same file system, or by any other criteria. If a<br />
dispatch method provides a general case, it is recommended that the method also create some<br />
kind of log for this action, so that there is a record of any continued operation that includes<br />
this general resolution.<br />
For example, the following implementation of %DispatchClassMethod allows the application<br />
user to invoke a method to perform whatever action was intended:<br />
ClassMethod %DispatchClassMethod(Class As %String, Method As %String, args...)<br />
{<br />
WRITE "The application has attempted to invoke the following method: ",!,!<br />
WRITE Class,".",Method,!,!<br />
WRITE "This method does not exist.",!<br />
WRITE "Enter the name of the class and method to call",!<br />
WRITE "or press Enter for both to exit the application.",!,!<br />
READ "Class name (in the form 'Package.Class'): ",ClassName,!<br />
READ "Method name: ",MethodName,!<br />
}<br />
IF ClassName = "" && MethodName = "" {<br />
// return a null string to the caller if a return value is expected<br />
QUIT:$QUIT "" QUIT<br />
} ELSE {<br />
// checking $QUIT ensures that a value is returned<br />
// if and only if it is expected<br />
IF $QUIT {<br />
QUIT $ZOBJCLASSMETHOD(ClassName, MethodName, args...)<br />
} ELSE {<br />
DO $ZOBJCLASSMETHOD(ClassName, MethodName, args...)<br />
QUIT<br />
}<br />
}<br />
By including this method in a class that is a secondary superclass of all classes in an application,<br />
you can establish application-wide handling of calls to non-existent class methods.<br />
188 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>