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.

attribute override

This notebook introduces attribute :>> override; after running it you can override an inherited attribute value on a named usage.

The previous notebook declared that the toaster must complete a cycle in at most 180 seconds, and added nominal, a usage of Toaster with no attribute values set. This notebook introduces attribute :>> override: a part usage can redeclare an inherited attribute with a specific value. We use it to build slow: not a design variant or an operating condition, but a fixture whose cycle time is a deliberately injected fault value, built to exercise the requirement’s failing branch.

part slow : Toaster {

slow is a named usage of Toaster, built to fail TimelyToast’s check. The open brace introduces a body where the inherited attribute will be overridden with a deliberately injected fault value.

    attribute :>> cycleTime = 200.0 [SI::s];

attribute :>> cycleTime redeclares the inherited cycleTime under slow. The :>> operator is a redefinition; it can only name an attribute that already exists in the type chain. The value it is bound to, 200.0 [SI::s], is a separate matter: writing = value with no default keyword gives a fixed binding, while default = value (which Toaster::cycleTime no longer has, since Chapter 1) would bind a value that a further usage could still override. slow’s 200 seconds is deliberately fixed and deliberately faulty: chosen to exceed TimelyToast’s 180-second bound, not to represent a plausible design point.

slow loads with its overridden cycleTime and no diagnostics. The next cell checks what :>> does when there is no inherited attribute to override.

Expected error: unresolved reference: nonExistent

With the negative control confirmed, the next cell looks up both nominal and slow in the loaded model.

nominal: ToasterDemo::nominal | kind: partUsage
slow   : ToasterDemo::slow | kind: partUsage
slow overridden attributes (1):
  ToasterDemo::slow::cycleTime

The slow fragments printed above loaded without error, and slow.attributes() confirms the override is now part of the model.

Try the chapter exercise in exercises/ch02/exercise.ipynb: create a hot usage of your BrewUnit with an overridden brewTemp and confirm the override loads.