Type Inheritance

This document describes the rules that developers of APS packages must follow when they create or use an APS type derived from other APS types.

Inheritance Rules

A derived type (a child) must have at least one implements property that refers to the parent type inherited by the child.

General rules when you declare an APS type (type-1) that implements another APS type (type-0):

  • You can add new properties, operations, or relations if their name attributes differ from the names of corresponding inherited elements (properties, operations, or relations).

  • You cannot delete properties, operations, or relations declared in the parent type (type-0).

  • If you need to add a definition of an attribute or change it in a property, operation, or relation, then the whole property, operation, or relation with all its attributes must be redefined in the derived type (type-1). Otherwise, the default values would be assigned to all non-defined attributes.

Properties and Structures

You can add new properties if their names differ from the name of the inherited properties:

../../../../_images/inheritance-new-property.png

However, you cannot change data declarations in a non-backwards-compatible manner. For example, you cannot change the type attribute:

../../../../_images/inheritance-change-type.png

Note

All that is described here about inheritance of properties works for structures as well.

Operations

When redefining an operation, only backwards-compatible changes in signatures are allowed. In fact, you can only add optional parameters. Those parameters must be declared after parameters of the base type.

Example:

/* Base Type */
{
  "stop": {
      "path": "/stop",
      "verb": "PUT",
      "parameters": { }
  }
}
/* Derived Type */
{
   "stop": {
      "path": "/stop",
      "verb": "PUT",
      "parameters": {
          "poweroff": { "kind": "query", "type": "boolean", "required": false }
      }
   }
}

Relationship

You can define new relations in derived types, however the name of a new relation should not match any of the relations of the base types.