Go to the first, previous, next, last section, table of contents.

Object Types

An object is a record paired with a method suite: a collection of procedures that operate on the object. The fields of an object are specified just like those of records (see section Record Types). Methods look like fields that hold procedure values. They are specified as follows:

A method signature is similar to a procedure signature (see section Procedure Types). If a procedure name follows ":=", the signature of the procedure must have as its first parameter an object of the type we are declaring; the rest of the parameters much match signature. The first parameter is often refered to as the self parameter.

Overrides specify new implementations for methods declared by an ancestor object-type:

where


Example

Let's create an object type Polygon which contains an open array of coordinates. We also have an initialization method, init, and a verification method, verify, which will be done by each subclass.


Type Drawable adds the draw method to Polygon and assigns the Draw procedure as the default implementation for the draw method.


Type Rectangle is a concrete implementation of an object. It will override the verify method to make sure there are four sides to this polygon and that the sides have the right properties.


Go to the first, previous, next, last section, table of contents.