Skip to main content
HealthShare Health Connect 2024.3
AskMe (beta)
Loading icon

Inheritance (Class Keyword)

Specifies the inheritance order for the superclasses of this class.

Usage

To specify the inheritance order for the superclasses of this class, use the following syntax:

Class MyApp.MyClass Extends (MySuperClass1, MySuperClass2) [ Inheritance = inheritancedirection ] { 
 //class members
}

Where inheritancedirection is left or right. You can also omit this keyword; in this case, InterSystems IRIS uses the default inheritance direction (left).

InterSystems recommends using left inheritance in all new programming.

Details

The Inheritance keyword specifies inheritance order for a class with multiple inheritance. A value of left for inheritancedirection specifies left-to-right inheritance and a value of right specifies right-to-left inheritance.

For example, consider class X, which inherits from classes A, B, and C as follows:

Class X Extends (A, B, C) 
{
}

The default inheritance order for the class compiler is from left to right, which means that differences in member definitions among superclasses are resolved in favor of the leftmost superclass (in this case, A superseding B and C, and B superseding C.)

Specifically, for class X, the values of the class parameter values, properties, and methods are inherited from class A (the first superclass listed), then from class B, and, finally, from class C. X also inherits any class members from B that A has not defined, and any class members from C that neither A nor B has defined. If class B has a class member with the same name as a member already inherited from A, then X uses the value from A; similarly, if C has a member with the same name as one inherited from either A or B, the order of precedence is A, then B, then C.

To specify right-to-left inheritance among superclasses, use the Inheritance keyword with a value of right:

Class X Extends (A, B, C) [ Inheritance = right ]
{
}

With right-to-left inheritance, if multiple superclasses have members with the same name, the superclass to the right takes precedence.

Notes on Right Inheritance

Even with right-to-left inheritance, the leftmost superclass (sometimes known as the first superclass) is still the primary superclass. This means that the subclass inherits only the class keyword values of its leftmost superclass — there is no override for this behavior.

Also with right-to-left inheritance, when you modify and recompile a superclass, it is necessary to manually recompile the subclasses.

Effect on Subclasses

This keyword is not inherited.

Default

If you omit this keyword, the inheritance order is left.

See Also

FeedbackOpens in a new tab