1
votes

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
So, what the question? As for me, you already answered your question, what you need more. The only thing which is strange, how you named your classes. You have to two classes, which you named as ChildClass and one inherited class which is BaseClass.DAiMor
@DAiMor My question is the last sentence "I don't know how cache supports this(unlikely to other programming language)."Vivek Ranjan
what do you mean by? "how cache supports this' posted below is the extensive explanation in the documentation, do you have any questions beyond that?kazamatzuri

1 Answers

4
votes

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.