Constraining Type of Replaceable Elements

1 General Description

A declaration of a replaceable element of a class can represent either a variable (as comp1 in MicroCircuit) or a local class declaration (as type CompType = Resistor in GenMicroCircuit2). The extends keyword in the second form has nothing to do with inheritance, it is just a reuse of the keyword for a different purpose. It is however recommended to avoid modifiers in the constraining type (the expression after the extends keyword).


2 MicroCircuit



In the class
TempMicroCircuit the instance comp1 is modified to have the type TempResistor instead of Resistor.




A more generic circuit expressing the same thing as
TempMicroCircuit.




Type Error,
Inductor is not subtype of Resistor. By extending CompType = Resistor with TwoPin the redeclaration can be successfully done.



3 Electrical Units



4 Connectors


5 Component TwoPin


6 Generic MicroCircuit

After changing the GenMicroCircuit class there is no problem to define a more specific circuit, e.g. using the component type Capacitor.





The
CapacitorMicroCircuit has no replaceable CompType declaration left since the original replaceable declaration was replaced. Therefore we need to perform a redeclaration with redeclare replaceable to be able to perform further modifications.




The constraining type of a replaceable redeclaration must be a subtype of the constraining type of the declaration it redeclares. This condition is fulfilled for
GenCapacitorMicroCircuit above, since the constraining type GenCapacitor is a subtype of TwoPin. Thus the modifier R = 20 in the definition of MicroCircuit3 is propagated to both the declaration and the constraining type, which is apparent in the class MicroCircuit3expanded.






In an element redeclaration of a replaceable element the modifiers of the replaced constraining type are merged to both the new declaration and to the new constraining type. The modifier
R=30 for the constraining type Resistor below is propagated to the new type TempResistor2 and the new constraining type Resistor2.