Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

composition

This notebook introduces part usage (composition); after running it you can declare that a system definition owns named instances of its subsystem types.

The previous notebook declared that Toaster specializes ToastingSystem. This notebook completes Toaster’s declaration: a cycle-time slot with no value yet, and named parts for its heating and control subsystems. The model is now structurally complete for Chapter 1.

part def Toaster :> ToastingSystem {

Every notebook in this chapter loads the same already-complete models/ch01-cumulative.sysml, so there is no partial Toaster in this chapter for one notebook to hand off to the next. Notebook 03’s bare Toaster :> ToastingSystem; and this notebook’s full declaration are each an illustrative fragment, checked independently by check_construction.py against a minimal stub, showing what one step of Editor-API authoring would add once the API supports it, not a live patch to a running model. The real continuation mechanism is between chapters, not within one: each chNN-cumulative.sysml is a file on disk, and the next chapter’s file is authored to include everything the previous one has, plus its own new declarations.

    attribute cycleTime : ISQ::DurationValue;

cycleTime is a typed, unit-bearing slot with no value: how long a cycle actually takes is a result the design produces, derived later from the mechanism and the energy balance, not a number chosen here.

    part heating : HeatingSystem;
    part control : ControlSystem;

Each part usage declares that Toaster owns one instance of its type. heating : HeatingSystem means there is one heating subsystem per toaster: the heating subsystem exists inside the Toaster, not just pointed to by it. These are structural ownership relationships, not Python-style references.

The complete Toaster body loads with no diagnostics. The next cell checks what happens when a part usage names a type the model does not have.

Expected error: unresolved reference: UndefinedSubsystem

Composing an undefined type raises an unresolved-reference error, reported in bad.diagnostics[0].

Toaster parts (2):
  ToasterDemo::Toaster::heating
  ToasterDemo::Toaster::control
Toaster attributes (1):
  ToasterDemo::Toaster::cycleTime

Diamond arrows show heating and control as parts Toaster owns; dashed arrows show each typed by its own part definition.

Loading...

The diagram redraws what parts() reported above, now showing heating and control each typed by its own definition.

toaster.parts() returns the two part symbols and toaster.attributes() returns cycleTime, confirming the composition is now part of the model.

The assembled Toaster declaration loaded without error, and the diagram above confirms heating and control are part of the model.

Try the chapter exercise in exercises/ch01/exercise.ipynb: compose a CoffeeMaker from BrewUnit and HeatExchanger and verify both parts appear via parts().