constructed types

We have not yet dealt with "constructed types" which have a special syntax in the models and for data entry. ?TShirt contains a single constructed type which is indicated by the "#" character:

         Composition ?Country #Components
The label "Composition" is followed by two fields. "?Country" is an ordinary class of the sort we have already considered, and "#Components" is a constructed type. The model assumes that we have already defined ?Country (we won't show it here) and the ?Components class which perhaps looks like this:

?Components Dye Text ?Manufacturer
            Cloth Text ?Manufacturer
Although a constructed type looks like a single indivisible field, it is really much more. Think of a constructed type field as representing an entire class that can be grafted like an extension onto other classes, even to several places in the same class. The #XXXXX is in a sense an abbreviation for the graft. The extension can be as complex as an "ordinary" class with multiple labels, fields, and links.

data entry

When a class is used as a constructed type it is no longer an independent entity and data should not be entered directly into it. Instead, the data is entered at the level of the class that refers to it in the first place--i.e., the "host" class that is using the constructed type as an extension. For example, for a TShirt one might enter:

TShirt : sam29
Composition France Dye Orange-22 DuPont
Composition Mexico Dye Red-15 DuPont
Composition Canada Dye Blue-08 Monsanto
Composition Brazil Cloth Cotton Cannon
Look carefully at the data syntax. It contains a feature you have not seen elsewhere: data and labels are interspersed. Nonetheless this syntax follows the more general rule that data entry requires a label to position the incoming data properly; i.e., data is presented in a label--data pair which allows ACEDB to locate the appropriate field for the data. When a constructed type is grafted onto a model this rule still holds and one must specify labels if the structure of the constructed type requires them.

The resulting display (which we have scrolled slightly to the right) is:

Notice that the interspersed labels appear in the display. For example, both "Composition" and "Dye" are labels; sandwiched between them is "France" which is data. Interspersed labels can be very helpful to users who might otherwise be confused by a series of ambiguous fields. You cannot accomplish this with an "ordinary" model, e.g. using the structure:

   Composition ?Country Dye Text ?Manufacturer    //***WRONG***
                        Cloth Text ?Manufacturer //***WRONG***

reuse of constructed types

A single constructed type can be grafted onto a class in more than one place. It would be entirely legal to modify ?TShirt to include a structure like this:

   Composition Body #Components
               Lining #Components
This circumvents another restriction, namely that labels can be used only once per class definition since now the labels "Dye" and "Fabric" can appear in two different contexts.

modularization

Constructed types allow you to modularize structures that may need to be reused, perhaps many times, in the models file. For example, if color categories occur in several classes, then this structure:

                  Background Red
                             Green
                             Purple
                             Grey
                             Blue
can be profitably rendered
 
                  Background #Color
where ?Color is defined as

?Color Red
       Green
       Purple
       Grey
       Blue

Show me the whole t-shirt model again.

Back to Table of Contents