Module 5 — Inheritance, Components & Advanced Modeling


🎯 Module Objective

By the end of this module, you will:

This module separates intermediate modelers from architects.


1️⃣ Why Advanced Modeling Matters

In real systems, you will not have:

You will have:

Without reuse → your models become messy and duplicated.

Advanced modeling solves this.


2️⃣ Inheritance in DTDL (extends)

Inheritance allows one model to reuse another model.

Example:

You have a base model called Device.

{
  "@id": "dtmi:com:smartfactory:Device;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "displayName": "Device",
  "contents": [
    {
      "@type": "Property",
      "name": "serialNumber",
      "schema": "string"
    },
    {
      "@type": "Property",
      "name": "operationalStatus",
      "schema": "string"
    }
  ]
}

Now you want a TemperatureSensor.

Instead of rewriting everything, you extend:

{
  "@id": "dtmi:com:smartfactory:TemperatureSensor;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "extends": "dtmi:com:smartfactory:Device;1",
  "displayName": "Temperature Sensor",
  "contents": [
    {
      "@type": "Telemetry",
      "name": "temperatureReading",
      "schema": "double"
    }
  ]
}

Now TemperatureSensor automatically inherits:

Plus its own telemetry.

This keeps your system clean.


3️⃣ When to Use Inheritance

Use extends when:

Example:

Base: Equipment
Extended:

All inherit:


4️⃣ Multiple Inheritance

DTDL supports extending multiple interfaces.

Example:

"extends": [
  "dtmi:com:smart:Device;1",
  "dtmi:com:smart:PowerConsumer;1"
]

This allows combining behaviors.

Use carefully.

Avoid overly complex inheritance trees.


5️⃣ Components — Composition Modeling

Components allow you to embed one model inside another.

This is NOT the same as relationships.

Think:

Inheritance → “is a”
Component → “has a”

Example:

A Machine has a Motor.

First define Motor:

{
  "@id": "dtmi:com:smartfactory:Motor;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "displayName": "Motor",
  "contents": [
    {
      "@type": "Property",
      "name": "rpm",
      "schema": "double"
    }
  ]
}

Now embed it inside Machine:

{
  "@id": "dtmi:com:smartfactory:Machine;1",
  "@type": "Interface",
  "@context": "dtmi:dtdl:context;2",
  "displayName": "Machine",
  "contents": [
    {
      "@type": "Component",
      "name": "motor",
      "schema": "dtmi:com:smartfactory:Motor;1"
    }
  ]
}

Now Machine has a motor component.


6️⃣ Relationship vs Component (Critical Difference)

Feature Relationship Component
Creates graph edge Yes No
Separate twin instance Yes No
Used for topology Yes No
Used for composition No Yes
Independent lifecycle Yes No

If the entity should exist independently → Relationship.

If it is part of the entity → Component.


7️⃣ Real-World Design Pattern

Smart Factory Example:

Machine:

This is layered modeling.


8️⃣ Enterprise Modeling Strategy

Professional modeling approach:

  1. Define base interfaces
  2. Extend for specialization
  3. Use components for internal parts
  4. Use relationships for topology

Think modular.


9️⃣ Avoid These Mistakes

❌ Deep inheritance chains
❌ Using component instead of relationship
❌ Copy-pasting properties across models
❌ Mixing composition and topology

Architectural rule:

Use inheritance for shared structure. Use components for internal composition. Use relationships for graph connectivity.


🔟 Designing for Scale

Imagine:

1,000 machines
10 machine types
5 shared subsystems

Without reuse → 50 repeated definitions.

With inheritance + components → clean modular system.

This becomes critical at enterprise scale.


1️⃣1️⃣ Modeling Exercise

Design a Smart Car.

Car:

Think carefully:

Is Engine a component or relationship?

Answer: Component (it is part of the car)

Is ChargingStation a component?

No. It exists independently. So → Relationship.


🧠 Key Takeaways

You are now thinking like a system architect.


🚀 What’s Next?

In Module 6 we go deep into:

This is where your models become fully expressive.

You are now building enterprise-grade DTDL.

💬
AI Learning Assistant