[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
CREATE CLASS
Synopsis
Begin a class specification
Syntax
CREATE CLASS <class name>
[INHERIT <superclass name>]
[METACLASS <metaclass name>]
[STATIC][FUNCTION <function name>]
Arguments
<class name> is the name of the class to be created. This name
follows the same rules as those governing Clipper function names.
<superclass name> is the name of the class from which the new
class should be inherited. If omitted, the new class will have the
superclass Object (the default superclass of all classes). If
more than one class is specified (separated by commas), a multiply-
inherited class is created. See the section on Multiple
Inheritance.
<metaclass name> is the name of the metaclass which should be
used to instantiate this class. This is an advanced feature which
is not necessary in normal programming. See the section on
Metaclasses for more information.
STATIC specifies that the class function for this class
will be declared as a static function, thus will not be accessible
outside the current module.
FUNCTION <function name> specifies a name for the class
function which is different from the class name.
Description
Begins a class specification. A class specification is a sequence
of Class(y) commands, beginning with CREATE CLASS and ending
with END CLASS, which constitute the structure of a given
class, ie. the names of all variables, messages and methods
contained in that class.
Class members (variables, messages and methods) declared after a
CREATE CLASS command are considered hidden by default. This
means that they cannot be accessed outside the methods of their
class (see the HIDDEN: command). The EXPORT: and
PROTECTED: commands can be used to achieve a visibility other
than the default.
All of the commands defined in this chapter can be used after
CREATE CLASS to specify the structure of a class. Some of the
most commonly used commands are:
VAR
METHOD
MESSAGE...METHOD
CLASS VAR
CLASS METHOD
CLASS MESSAGE...METHOD
EXPORT:
PROTECTED:
HIDDEN:
These commands are collectively referred to as class declaration
commands. Refer to their individual entries for more information.
Once the desired class structure has been declared using these
commands, END CLASS is used to end the class specification.
After the END CLASS command has appeared, the METHOD
definition command can be used to define the methods which
were declared in the class specification.
Example
A complete definition of a simple Box class follows. The class
specification declares four instance variables and two methods.
The methods are defined after the class specification.
#include "class(y).ch"
CREATE CLASS Box
VAR top, left, bottom, right
EXPORT:
METHOD init
METHOD draw
END CLASS
METHOD init( nTop, nLeft, nBottom, nRight )
::top := nTop
::left := nLeft
::bottom := nBottom
::right := nRight
RETURN self
METHOD draw()
DispBox(::top, ::left, ::bottom, ::right)
RETURN self
Notes
It is best to define only one class per module (single .PRG file).
This is to avoid problems in distinguishing between methods of the
same name, such as init, which most classes implement.
The CREATE CLASS command actually generates a Clipper function
with the same name as the class. This is explained further under
the Class Functions and Class Objects sections.
See Also
END CLASS, Class Functions, Class Objects,
Multiple Inheritance, Metaclasses
See Also:
END CLASS
Class Functions
Class Objects
Multiple Inheritance
Metaclasses
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson