PRISM
All lessonsLesson 3 of 9 · about 20 minutes

Hierarchy and variants

Learn how SysML v2 derives a more specific definition from a general one: specialization with :>, redefinition with :>>, multiplicity such as [2] and [0..1], and a first look at subsetting. With exercises, for beginners and SysML v1 users.

After this lesson you can

  • Derive a more specific definition with :> (specializes)
  • Replace an inherited feature with :>> (redefines) and give it a value
  • State how many of a part there are with multiplicity: [2], [0..1], [1..*]
  • Recognise subsetting as :> on a usage

The coffee machine of lessons 1 and 2 is one model. Now we need a variant: an espresso machine that has everything the coffee machine has, plus a bit more. SysML v2 does not copy for this. It derives the new definition from the old one.

Specializing a definition

part def EspressoMachine :> CoffeeMachine; means: an espresso machine is a kind of coffee machine. The symbol :> after a definition reads specializes. You can also write the word: part def EspressoMachine specializes CoffeeMachine;.

The specialized definition inherits all features of the general one: tank, pump, boiler and brew unit. It can add its own.

// Excerpt of the coffee machine model
part def EspressoMachine :> CoffeeMachine {
    part milkFrother : MilkFrother;
}

Multiplicity

How many cup holders does an espresso machine have? A multiplicity in square brackets after the type answers that. [2] means exactly two. [0..1] means none or one, so the part is optional. [1..*] means at least one, with no upper limit. [*] means any number.

Multiplicity works for every usage, not only for parts.

// Excerpt of the coffee machine model
part def EspressoMachine :> CoffeeMachine {
    part cupHolder : CupHolder[2];
    part milkFrother : MilkFrother[0..1];
}

Redefining an inherited part

An espresso machine needs a stronger pump. The inherited pump is typed Pump; we want it typed HighPressurePump. We do not add a second pump. We redefine the inherited one with :>>, which also reads redefines.

A redefinition replaces the inherited feature inside the specialization. The new type has to be a specialization of the old one: HighPressurePump specializes Pump.

// Excerpt of the coffee machine model
part def HighPressurePump :> Pump;

part def EspressoMachine :> CoffeeMachine {
    part :>> pump : HighPressurePump;
}

Redefining an attribute value

Attributes are redefined the same way. The Pump has a power without a value. The special pump redefines it and sets a value, so it is filled in for this definition only.

The redefining attribute declares neither a name nor a type: it takes both from the attribute it redefines.

// Excerpt of the coffee machine model
private import ISQ::*;
private import SI::*;

part def Pump {
    attribute power : PowerValue;
}

part def HighPressurePump :> Pump {
    attribute :>> power = 60 [W];
}

Subsetting in a nutshell

On a usage, :> means subsets (subsets in words). Whatever the subsetting usage stands for is also a thing of the other one. If an espresso machine has two cup holders, leftHolder can be one of them.

Redefinition is a special case of subsetting that replaces the inherited feature instead of adding another. So: :> after a definition specializes, :> after a usage subsets, :>> redefines.

// Excerpt, subsetting
part def EspressoMachine :> CoffeeMachine {
    part cupHolder : CupHolder[2];
    part leftHolder : CupHolder[1] :> cupHolder;
}

Our model so far

The machine with its attributes from lesson 2 and the new espresso variant. The special pump is your task below. In lesson 4 all of these parts get ports and are connected.

// The coffee machine model of this lesson
package CoffeeMachine {
    doc /* A fictional coffee machine, modelled step by step in the PRISM learning module. */

    private import ScalarValues::*;
    private import ISQ::*;
    private import SI::*;

    part def WaterTank {
        attribute capacity : VolumeValue = 1.5 [L];
    }

    part def Pump {
        attribute power : PowerValue;
    }

    part def Boiler {
        attribute waterTemp : TemperatureValue = 368.15 [K];
        attribute heatingPower : PowerValue = 1200 [W];
    }

    part def BrewUnit {
        attribute brewTime : DurationValue = 25 [s];
    }

    part def CoffeeMachine {
        attribute modelName : String = "Aroma One";
        part tank : WaterTank;
        part pump : Pump;
        part boiler : Boiler;
        part brewUnit : BrewUnit;
    }

    part def CupHolder;
    part def MilkFrother;

    part def EspressoMachine :> CoffeeMachine {
        part cupHolder : CupHolder[2];
        part milkFrother : MilkFrother[0..1];
    }
}

Source

Statements follow the OMG SysML v2 specification, Part 1 (Language Specification), in the clauses on definition and usage (specialization, subsetting, redefinition) and on multiplicity, and the KerML specification, which defines these relationships for all feature kinds.

Try it

This is the coffee machine model of the lesson: the CoffeeMachine and an EspressoMachine derived from it. The diagram shows the espresso machine with the parts it inherits and the ones it adds. Multiplicities such as [2] are in the text, the diagram does not draw them. Edit the text; the diagram redraws while you type. Everything runs in your browser, nothing is sent anywhere. At the end of the page you can download the file and open it in any tool that reads SysML v2 textual notation.

The editor loads when you scroll here.

The editor contains open-source components. Third-party notices · Source offer

Exercises

10 short exercises. Every answer gets feedback right away. Exercises you get wrong come back at the end. Your progress stays in this browser.

Exercise 1 of 10

Match each SysML v1 term to its SysML v2 counterpart.

SysML v1SysML v2

Generalization between Blocks
Redefinition of a Part Property
Multiplicity 0..1
Subsetting of a Property

Exercise 2 of 10

Which parts does an EspressoMachine have?

part def CoffeeMachine {
    part tank : WaterTank;
    part pump : Pump;
}

part def EspressoMachine :> CoffeeMachine {
    part milkFrother : MilkFrother;
}

Exercise 3 of 10

An espresso machine is a kind of coffee machine. Which symbol completes the line?

part def EspressoMachine ___ CoffeeMachine;

Exercise 4 of 10

Arrange the pieces into the definition of EspressoMachine as a specialization of CoffeeMachine.

Drag the pieces, or use the arrow buttons.

  • ;
  • CoffeeMachine
  • def
  • :>
  • part
  • EspressoMachine

Exercise 5 of 10

Tap the line that is not valid SysML v2.

package CoffeeMachine {
    part def CoffeeMachine;
    part def EspressoMachine redefines CoffeeMachine;
}

Tap a line, or move to it with the Tab key and press Enter.

Exercise 6 of 10

Which line says that an espresso machine has exactly two cup holders?

part def EspressoMachine :> CoffeeMachine {
    // which line gives the cup holders?
}

Exercise 7 of 10

The milk frother is optional: a machine has none or one. Type the multiplicity range.

part milkFrother : MilkFrother[___];

Exercise 8 of 10

What does part :>> pump : HighPressurePump; do inside EspressoMachine :> CoffeeMachine?

Exercise 9 of 10

Tap the line that is not valid SysML v2.

part def EspressoMachine :> CoffeeMachine {
    part cupHolder : CupHolder[2];
    part redefine pump : HighPressurePump;
}

Tap a line, or move to it with the Tab key and press Enter.

Exercise 10 of 10

HighPressurePump :> Pump should have a power of 60 watts. The Pump declares attribute power : PowerValue;. Which line redefines it with that value?

part def HighPressurePump :> Pump {
    // which line sets the power?
}

Take the model with you

The coffee machine model as a SysML v2 text file.

Download coffee-machine.sysml

See it as a diagram

PRISM turns SysML v2 text like this into diagrams and views. Try it on the sample model.

Try it now
Next lesson

Ports and items

Where the parts of the machine exchange water, power and coffee.