Resource inheritance

Resource inheritance is an advanced technique used to reduce repetition when creating Ilograph Diagrams.

Often, resource trees will have multiple instances of the same kind of resource, leading to lots of repetition. For example, when diagramming a computer network, you might have many identical network switches, each with the same number of ports. More specifically, if you had two identical 3-port switches, named Switch A and Switch B, it would look like the following when defined in IDL:

resources:
- name: Switch A
  subtitle: Network Switch
  color: navy
  description: A three-port switch
  abstract: true
  children:
    - name: Port 1
    - name: Port 2
    - name: Port 3

- name: Switch B
  subtitle: Network Switch
  color: navy
  description: A three-port switch
  abstract: true
  children:
    - name: Port 1
    - name: Port 2
    - name: Port 3

Being identical, but distinct, resources, Switch A and Switch B have identical properties. We can cut down on this repetition, and formalize this “is-a” relationship, using resource inheritance. We’ll start by declaring a new resource, called Switch, and declaring it as abstract:

resources:
- name: Switch
  subtitle: Network Switch
  color: navy
  description: A three-port switch
  abstract: true
  children:
    - name: Port 1
    - name: Port 2
    - name: Port 3

Next, we’ll redefine Switch A and Switch B to be instances of Switch:

resources:
...
- name: Switch A
  instanceOf: Switch
  
- name: Switch B
  instanceOf: Switch

And with that, both Switch A and Switch B have all the properties of Switch, including its children. If desired, we can override any of the inherited properties (except children, see note below) by simply defining them on Switch A or Switch B.

Both switches and their ports can be referenced in perspectives as usual. Abstract resources, however, cannot be referenced in perspectives. We’ll round out this example by adding six Terminal resources and use them all in a simple perspective, called Network:

resources:
...
- name: Alpha
  subtitle: Terminal
- name: Bravo
  subtitle: Terminal
- name: Charlie
  subtitle: Terminal
- name: Delta
  subtitle: Terminal
- name: Echo
  subtitle: Terminal
- name: Foxtrot
  subtitle: Terminal
    
perspectives:
- name: Network
  relations:
    - from: Alpha
      to: Switch A/Port 1
    - from: Bravo
      to: Switch A/Port 2
    - from: Charlie
      to: Switch A/Port 3
    - from: Delta
      to: Switch B/Port 1
    - from: Echo
      to: Switch B/Port 2
    - from: Foxtrot
      to: Switch B/Port 3

Notice that we reference the resources as usual here; perspectives are agnostic to whether resources use inheritance or not. When rendered, this example looks like so:

You find this complete example in the ilograph app.

Detailed inheritance rules

  • You can define abstract resources at any level in your resource tree.

  • Resources can implement abstract resources it shares a parent, grand-parent, etc. with. In other words, the abstract resource must be at the same level or higher in the resource tree than the implementing resource.

  • Multiple inheritance is not supported.

  • Resources that implement abstract resource can define their own children in addition to children defined by the inherited resource. A defined child resource will replace an inherited child resource if they have the same id/name.

  • Abstract resources can implement other abstract resources, but only from abstract resources that are higher in the resource tree.

Last updated on 18 Apr 2021
Published on 18 Apr 2021