Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Class Type
◄Structured Types► ◄Contents► ◄Index► ◄Back►
TYPE
<identifier> = OBJECT[ ( <parent class> ) ]
<data fields>
<methods>
END
Description
A class is a template defining an object. It is an object type. A
class declares one or more <data fields> and the <methods> that
manipulate them. A class can inherit the data fields and methods of
an existing or "parent" class. The name of the parent class is
given in the optional parentheses after OBJECT. It is an error
to list more than one class within the parentheses.
<data fields>
The declaration of one or more data structures. Use the same syntax
that declares the fields of a record.
<methods>
A list of method declarations. Each method declaration is like
a procedure or function heading except that the name may be
qualified with the name of the class (class_name.method_name). For
example, note how each method name in the following shape object
begins with 'shape.'. Although not required, such a qualification
is good programming style.
To create an object, first declare a class:
TYPE
shape = OBJECT
color : colors;
height, width : Integer;
PROCEDURE shape.init;
PROCEDURE shape.draw;
PROCEDURE shape.move( horz, vert : Integer );
FUNCTION shape.area : Real;
END;
Then declare an instance of the class:
VAR
a_shape : shape;
Finally, allocate memory for the new object:
BEGIN
.
New( a_shape );
.
END.
See also: INHERITED, Member, OBJECT, OVERRIDE