21: Using Class Families

  1. Deriving a class from a class family
    1. A class family is not a class; it's a class-producing template
    2. A class family uses formals in its definition to specify a yet-to-be-determined type. The formal is used throughout the class family definition wherever that type is specified.
    3. A class is derived from a class family, not defined as standard classes are.
      1. Derivation requires no class definition, simply a declaration of the class. The declaration supplies the necessary actuals to satisfy the class's formals.
      2. If actuals aren't supplied in a declaration, the class family creates its default class. (For example, List(1,2,3) is defined to be List[Object, Equal](1,2,3).
  2. Defining a class family
    1. A class family definition takes the same form as a class definition with these exceptions:
      1. A list of formals appears in brackets after the "class" keyword.
        1. Each formal is listed with an identifier followed by a colon and the keyword "Class".
        2. A formal may also be followed by a colon, the keyword "Class", the symbol "<:" and a class specifier (a class ID). This means that the only classes that will satisfy this formal is the specified class and its subclasses. If no class is specified, any classes that are subclasses of Object will satisfy the formal.
      2. Each formal identifier can be used in the superclasses and feature definitions that follow wherever a class identifier can be used.
        1. There is one exception: it can't be used in the superclasses to designate the immediate flavor superclass.
        2. When a class is derived, the formal identifier is replaced with the actual (a class) to derive the new class.
      3. A class family can be created to inherit from a class, or it can be created to inherit from another class family.
        1. If it's created to inherit from another class family, it may satisfy that family's formals, or it may tie its formals to the superclass family's formals. If so, the actuals used to derive a class satisfy the formals of both the class family and its superclass family

TS Ref - 26 JUN 1996

Generated by the sweat of Mike Boom's brow.