Does object script supports multiple inheritance?

264 views Asked by At

I am new to cache and found something different from normal oop concept. In object script a base class can be inherited from multiple subclasses(inheritance order can be left/right). If objectscript is oop, I don't know how cache supports this(unlikely to other programming language).

BaseClass

  Class Inheritance.TheBaseClass Extends (%RegisteredObject, 
  Inheritance.TheChildClass, Inheritance.TheChildClass1) [ Inheritance = left ]
  { 
     ClassMethod Init()
     {
      //do ##class(Inheritance.TheChildClass).Ping()
      //do ##class(Inheritance.TheChildClass1).Ping()
      do ..Ping()
      do ..Pingggg()
      }

   }

Child Class 1

 Class Inheritance.TheChildClass Extends %RegisteredObject
 {

   ClassMethod Ping()
   {
        Write "I am in Inheritance.TheChildClass",!
    }

 }

Child Class 2

Class Inheritance.TheChildClass1 Extends %RegisteredObject
{

  ClassMethod Ping()
  {
    Write "I am in Inheritance.TheChildClass1",!
  }

  ClassMethod Pingggg()
  {
    Write "I am in Inheritance.TheChildClass1111111111",!
   }

  }

Output

I am in Inheritance.TheChildClass

I am in Inheritance.TheChildClass1111111111

1

There are 1 answers

0
adaptun On

Documentation explains this clearly: http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GOBJ_classes#GOBJ_classes_inheritance

For example, if class X inherits from classes A, B, and C, its definition includes:

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.