7.2 Initial class definitions

We start with these simple, initial class definitions:

// Superclass of all position classes
define class <position> (<object>)
end class <position>; 
define class <absolute-position> (<position>)
  slot latitude;
  slot longitude;
end class <absolute-position>;
define class <relative-position> (<position>) 
  slot distance;
  slot angle;
end class <relative-position>; 

These initial definitions show the inheritance relationships among the classes, and the names of the slots show the information that the classes must provide. At this point, we omit the type declarations of the slots, which is equivalent to specifying the type <object>. We will fill in the implementation later, by deciding on the types of the slots, and providing the say methods.

Our requirements mention only <absolute-position> and <relative-position>, but we choose to define a superclass of both of them, named <position>.

Modularity note: The benefits of defining the <position> class are these:

  • The <position> class creates an explicit relationship between the other position classes, which are related conceptually.

  • We can use the <position> class as the type of a slot or other object, in cases where either an absolute or relative position is appropriate.