davidbprice
davidbprice

Reputation: 1

Can an abstract class be embedded in another class?

The documentation says

Abstract classes are essential to support Object Orientation without the typical spamming of the database with always empty auto-created clusters.

But it also says

A class that can't have instances

However, I would like to embed a list class B in class A, not have class A inherit from the abstract class B. Is this allowed? Example:

enter code here
propVal {
  locType : ""
  eleName : ""
  ...
  values :[valueStamp]
}

valueStamp {
  value : any,
  stamp : actionStamp
}

actionStamp{
 // various attributes that say who, when, where change was made
}

Is used in many classes keeping track of changes to various fields. They will never be used stand alone, but can't inherit because they can be used more than once in a class Sample parent class

classA{
    helperAId:"",
    helperAProps : embeddedList of PropVals,
    helperBId : "",
    helperBProps : embeddedList of PropVals
}

Upvotes: 0

Views: 449

Answers (1)

rmuller
rmuller

Reputation: 12859

  • Important: The class hierarchy supported by OrientDB is similar to OO principles as implemented by popular languages like Java. However, it is not the same, so there are important differences!
  • Yes you can embed a (list of) class(es) of type B in a class type A. This is perfectly valid and a much used construct. This is done using the EMBEDDED type.
  • OrientDB does not support the concept of interfaces or mixin's, just classes and abstract classes. So a class can only inherent (extend) a single parent class. In your use case I would create an abstract ActionStamp class (or whatever you name it) and let your other classes extend it.The B and A classes can both extend this ActionStamp class

So, using your example: CREATE ABSTRACT CLASS propVal ... CREATE CLASS A CREATE PROPERTY A.helperAProps EMBEDDEDLIST propVal ...

Upvotes: 1

Related Questions