Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Inheritance

Like many modern languages, Types can also a Java or C++ Class, a C3.ai Type can inherit fields and methods from other types in an object oriented fashion. The keywords which signal inheritance are `mixes` and `extends`. These follow the name of the new type.C3.ai Types. The keywords`mixes` and `extends` signal inheritance. These keywords follow the new C3.ai Type's name in your .c3typ file (e.g., type SmartBulb extend)

These two keywords signal different kinds of Type Where C3 Type inheritance differs from other languages, is that these two keywords signal two different types of inheritance.

Mix-ins

This most basic Mix-ins are the most common type of inheritance is and signaled by the 'mixes' keyword. When a type C3.ai Type 'mixes' another typeC3.ai Type, it inherits all of the fields and methods of that type. The new type gets its own schema and table, and the user can go on to use it as they normally would.the original C3.ai type. In general, mix-ins are used to incorporate non-persistable types. The new C3.ai Type is stored in a new table and has its own schema. 

Code Block
type ParentType {
    fieldA: int
    funcA: function(): ReturnType
}

type ChildType mixes ParentType {
    fieldB: double
    funcB: function(): ReturnType
}

In this example, ChildType also includes the field and method defined in the parent typemixes ParentType, and inherits 'fieldA' and 'funcA' defined on ParentType.

Persistable Inheritance

This second type of Persistable inheritance is signaled by the 'extends' keyword. When a type C3.ai Type 'extends' another typeC3.ai Type, it inherits its fields and methods, but also resides in the same schema and table as the original type. In fact, a type can only extend a type which has been marked as `extendable`.all the original C3.ai Type's fields and methods. The extension and original C3.ai Types must be marked with 'entity' keyword and share the same database table. To distinguish data from the original and extension C3.ai Types, the C3 AI Suite adds a 'type key' field to this database table. Additionally, only C3.ai Types marked with the `extendable` keyword can be extended. 

Code Block
extendable entity type ParentType schema name "PRT_TYP" {
    fieldA: int
    funcA: function(): ReturnType
}

entity type ChildType extends ParentType type key "CHLD" {
    fieldB: double
    funcB: function(): ReturnType
}

In this example, ParentType is an extendable Persistable type stored in schema the table 'PRT_TYP'. ChildType extends ParentType and uses is also stored in the table 'PRT_TYP'.  Records associated with ChildType have 'type key' == 'CHLD', to distinguish them from ParentType's data.

To learn more about Type Inheritance, please see the C3.ai developer resources on Inheritance:Developer Resources here: 

...