Article Directory
-
Chapter 9 Caché Function Collection $CLASSNAME Function - Outline
- description
- Example
Chapter 9 Caché Function Collection $CLASSNAME Function
Returns the name of the class.
Outline
$CLASSNAME(n)
parameter
- n Optional-object reference (OREF) to the class instance. If omitted, the class name of the current class is returned.
description
$CLASSNAME
Returns the name of the class. Usually, it accepts an object reference (OREF) and returns the corresponding class name. $CLASSNAME
Return the name of the current class without parameters . $CLASSNAME
Always return the full class name (for example, %SQL.Statement
), not a short version of the class name with the package name omitted (for example, STATEMENT
).
$CLASSNAME
Functionally equivalent to %Library.Base
superclass %ClassName(1)
methods. $CLASSNAME
Functions %ClassName(1)
provide better performance than methods in returning full class names . To return a short version of the class name, you can use %ClassName()
or %ClassName(0)
.
Example
The following example creates an instance of a class. $CLASSNAME
Get the instance OREF and return the corresponding class name:
/// d ##class(PHA.TEST.Function).CLASSNAME()
ClassMethod CLASSNAME()
{
SET dynoref = ##class(%SQL.Statement).%New()
WRITE "instance class name: ",$CLASSNAME(dynoref)
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME()
instance class name: %SQL.Statement
In the following example, $CLASSNAME
the class name of the current class context is returned without parameters . In this case, it is a DocBook.Utils
class. This is the $this
same as the class name contained in the special variable:
/// d ##class(PHA.TEST.Function).CLASSNAME1()
ClassMethod CLASSNAME1()
{
WRITE "class context: ",$CLASSNAME(),!
WRITE "class context: ",$THIS
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME1()
class context: PHA.TEST.Function
class context: PHA.TEST.Function
The following example shows that $CLASSNAME
functions and %ClassName(1)
methods return the same value. It also shows the use %ClassName()
method (with no parameters or with 0 parameters) to return a short version of the class name:
/// d ##class(PHA.TEST.Function).CLASSNAME2()
ClassMethod CLASSNAME2()
{
CurrentClass
WRITE "current full class name: ",$CLASSNAME(),!
WRITE "current full class name: ",..%ClassName(1),!
WRITE "current short class name: ",..%ClassName(0),!
WRITE "current short class name: ",..%ClassName(),!!
ClassInstance
SET x = ##class(%SQL.Statement).%New()
WRITE "oref full class name: ",$CLASSNAME(x),!
WRITE "oref full class name: ",x.%ClassName(1),!
WRITE "oref short class name: ",x.%ClassName(0),!
WRITE "oref short class name: ",x.%ClassName()
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME2()
current full class name: PHA.TEST.Function
current full class name: PHA.TEST.Function
current short class name: Function
current short class name: Function
oref full class name: %SQL.Statement
oref full class name: %SQL.Statement
oref short class name: Statement
oref short class name: Statement