Previous Table of Contents Next


9.6.9. Type Categories

It was noted previously that a value is either an object or a reference. This corresponds to two kinds of type: reference types and expanded types.

If a class is declared as just

   class CLASS_NAME ...

it defines a reference type. The entities declared of that type denote references. In the declaration

   x: ACCOUNT

the possible runtime values for x are references, which are either void or attached to instances of class ACCOUNT.

Instead of class, however, you can use the double keyword expanded class, as in the library class definition

   indexing
       description: “Integer values”
   expanded class
       INTEGER
   feature  -- Basic operations
       infix “+” (other: INTEGER): INTEGER is
           do ... end
   ... Other feature declarations ...
   end  -- class INTEGER

In this case, the value of an entity declared as n: INTEGER is not a reference to an object, but the object itself—in this case, an atomic object, an integer value.

It is also possible, for some non-expanded class C, to declare an entity as

   x: expanded C

so that the values for x are objects of type C, rather than references to such objects. This is our first example of a type—expanded C—that is not directly a class, although it is based on a class, C. The base type of such a type is C.

Note that the value of an entity of expanded type can never be void; only a reference can. Extending the earlier terminology, an expanded entity is always attached to an object, atomic (as in the case of n: INTEGER) or composite (as in x: expanded ACCOUNT).

Expanded declarations make it possible to construct composite objects with subobjects, as in the following abbreviated class declaration (indexing clause and routines omitted):

   class CAR feature
       engine: expanded ENGINE
       originating_plant: PLANT
   end  -- class CAR

Figure 9.8 shows the structure of a typical instance of CAR:


FIGURE 9.8.  A composite object with reference and subobject.

This example also illustrates that the distinction between expanded and reference types is important not just for system implementation purposes but for high-level system modeling as well. To understand