menu

IDL Part 5: Resource Inheritance

This is part 5 of a series of posts on the Ilograph diagramming language (IDL). In part 3, we looked at the Ilograph resource tree. The resource tree defines your organization’s resources, and these resources are then used in perspectives. In this post, we’ll explore the intermediate topic of resource inheritance.

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 resources (but not the same resource), 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 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
  1. You can define abstract resources at any level in your resource tree.

  2. 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.

  3. Multiple inheritance is not supported.

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

That’s it! As always, please reach out to me at billy@ilograph.com or @ilographs on twitter with any questions.