Inner Subtypes

Inner subtyping refers to a group of related subtype definition mechanisms, and is allowed only with the following parent types:

  • SEQUENCE
  • SEQUENCE OF
  • SET
  • SET OF
  • CHOICE

In general, all of these mechanisms define constraints on the presence and/or values of the parent type's components. A value of the parent type is valid if it satisfies all of the constraints expressed in the subtype definition.

All inner subtype definitions begin with the words "WITH COMPONENT" or "WITH COMPONENTS" following the name of the parent type. These keywords are followed by one or more constraints enclosed in curly braces ("{" and "}").

Example

In the following example, the SEQUENCE type Parameters is defined, containing three fields. Two other types, RequestParms and ResponseParms are defined, each derived from Parameters using inner subtyping. In both cases, a "full specification" is used; all fields from the SEQUENCE, which appear in the two defined subtypes, are listed.

Parameters ::= SEQUENCE {
          requestID INTEGER,
          command   PrintableString OPTIONAL,
          result    ENUMERATED {success(0), failure(1)} OPTIONAL
}
RequestParms  ::= Parameters (WITH COMPONENTS {command})
ResponseParms ::= Parameters (WITH COMPONENTS {result})
LotsOfChoices ::= CHOICE { a INTEGER,
                           b BOOLEAN,
                           c OCTET STRING,
                           d PrintableString,
                           e UTCTime }
FewerChoice   ::= LotsOfChoices (WITH COMPONENTS { a, b, c })

The following examples illustrate a second way of defining RequestParms and ResponseParms. A "partial specification" is used in this case. Partial specifications begin with an ellipsis ("..."), and follow with a list of the OPTIONAL components from the parent type which must be present or absent in the subtype. These second definitions produce types which are equivalent to those defined with the full specification.

Inner subtype definitions can also use constraints on the values of the components of the parent type. In the example below, two types are defined based on Parameters, each of which specifies the existence of a certain element in the parent SEQUENCE and the legal value of that element. This could be used, for example, to define a constant value contained within a particular type.

RequestParms ::= Parameters
        (WITH COMPONENTS {..., command PRESENT,
                               result  ABSENT})

ResponseParms ::= Parameters
        (WITH COMPONENTS {..., command ABSENT,
                               result  PRESENT})

StartupRequestParms ::= Parameters
        (WITH COMPONENTS {...,
                  command ("Initialize") PRESENT,
                  result   ABSENT})

StartupResponseParms ::= Parameters
        (WITH COMPONENTS {...,
                  command ABSENT,
                  result (success) PRESENT})

Related Topics