07/25/2017
Hello everyone,
I have a question about inheritance in combination with MultiStateDiscreteType. Does a subtype have to take all values of the base type and can add additional values?
Is the address space shown below correct?
In the case of enums, I know that the subtype may only use a selection of values from the parent enum, but no new values can be added.
Best regards
Christian
05/30/2017
MultiStateDiscreteType variables do not have the same semantics of an Enumeration since every instance has its own set of values as specified in the EnumValues or EnumString property on the instance. This means subtypes of MultiStateDiscreteType do not/cannot restrict the allowed values. If you need the semantics of an Enumeration you should use a normal variable with an Enumeration DataType.
07/25/2017
Thank you very much for the answer. In my particular case, there is a need for an extensible “enum”, which contains a fixed set of values that must be included in every extension.
Randy Armstrong said
This means subtypes of MultiStateDiscreteType do not/cannot restrict the allowed values.
Are there any rules for inheritance of MultiStateDiscreteType? Do existing values still have to be included in the subtype? Can a subtype overwrite a value of the base class (change the name)?
E.g. Is this changing of values possible/intended?
Base type:
0: Off
1: On
Derived data type:
0: Off
1: Setup
2: Online
I hope that no values can be overwritten and that a set of predefined values is ensured in all subtypes.
In the end I need such a variable:
Variable: PowerState DataType=BasePowerstate
BasePowerState->EnumStrings
0: Off
1: On
ImplementationSpecific_PowerState_1((inherit from BasePowerState)->EnumString
0: Off
1: On
2: LowPowerMode
3: StandBy
…
Best regards
Christian
05/30/2017
If you want those semantics then use a DataItemType with a Enumeration DataType.
Clients are expected to read the EnumValues/EnumStrings Property for each instance of a MultiStateVariable so the inheritance hierarchy will not restrict the values. Subtypes of MultiStateVariable ony restrict the DataType that can be used (i.e. UInteger -> UInt32).
1 Guest(s)