Topics

Note Selector

Inheritance

Tuesday, October 15, 2024

Inheritance is supposed to be a significant feature of definitions and attributes. However, when inheritance was described previously, only the mechanisms for setting up inheritance within definition files were covered.

Here, inheritance will be explained in greater detail, including what it offers, how and when to use it, as well as why it greatly impacts the optimization of Layers data.

Definition Inheritance

Definition inheritance is useful for reusing attributes which greatly reduces the data required for Layers functionality.

When a definition inherits another, the attributes that belong to the base definition are inherited by the derived definition.

If an attribute from the derived definition has the same name as an attribute from the base definition, it either overrides or amends the base definition's attribute.

Attributes from a base definition can be referred to as base attributes.

Attribute Overriding

Attribute Overriding is useful for manipulating base definition attributes from a derived definition.

Attributes that override base attributes are referred to as override attributes.

Consider the following example from vtabbar.json, defined for the Vortex library:

{
  "Tab Bar": {
    "_include": "QLayers/qlwidget.json::Widget",
    "attributes": {
      "Corner Radii.Top Left": 3,
      "Corner Radii.Top Right": 3
    },
    "children": {
      // ...
    }
  }
}

In the above, the Corner Radii attributes defined by the 'Tab Bar' definition override the base attributes inherited from the 'Widget' definition.

Attribute Amending

Attribute amending allows derived definitions to provide additional states for base attributes.