%Extends()
To check if an object inherits from a specific superclass, call its %Extends() method, and pass the name of that superclass as the argument. If this method returns 1, then the instance inherits from that class. If it returns 0, the instance does not inherit from that class. For example:
MYNAMESPACE>set person=##class(Sample.Person).%New()
MYNAMESPACE>w person.%Extends("%RegisteredObject")
1
MYNAMESPACE>w person.%Extends("Sample.Person")
1
MYNAMESPACE>w person.%Extends("Sample.Employee")
0
%ClassName() and the Most Specific Type Class (MSTC)
Although an object may be an instance of more than one class, it always has a most specific type class (MSTC). A class is said to be the most specific type of an object when that object is an instance of that class and is not an instance of any subclass of that class.
For example, in the case of the GradStudent class inheriting from the Student class that inherits from the Person class, for instances created by the commands:
set MyInstance1 = ##class(MyPackage.Student).%New()
set MyInstance2 = ##class(MyPackage.GradStudent).%New()
MyInstance1 has Student as its MSTC, since it is an instance of both Person and Student, but not of GradStudent. MyInstance2 has GradStudent as its MSTC, since it is an instance of GradStudent, Student, and Person.
The following rules also apply regarding the MSTC of an object:
To determine the MSTC of an object, use the %ClassName() method, which is inherited from %RegisteredObjectOpens in a new tab
classmethod %ClassName(fullname As %Boolean) as %String
Where fullname is a boolean argument where 1 specifies that the method return a package name and class name and 0 (the default) specifies that the method return only the class name.
For example:
write myinstance.%ClassName(1)
(Similarly, you can use %PackageName() to get just the name of the package.)