CLASS
CLASS className [INHERITS className]
[DIM attribute {, attribute}]
subroutineDefinition
functionDefintition
END CLASS
Creates a new user-defined class. Single inheritance is supported. Class attributes are defined in the Dim section.
New instances of a class object are created by calling a constructor method with the same name of the class. For example:
' create a Point class
CLASS Point
DIM x, y
END CLASS
' create a point
p = Point()
p.x = 10
p.y = 20
Objects are automatically destroyed when there are no references to the object. If you want an object to be permanent, create it with the New keyword:
' create a Point class
CLASS Point
DIM x, y
END CLASS
' create a temporary point and assign some values
p1 = Point()
p1.x, p1.y = 10, 20
' create a permanent point and assign some values
p2 = NEW Point()
p2.x, p2.y = 40, 80
' destroy the temporary point
p1 = NOTHING
' This does not destroy the permanent point
p2 = NOTHING
To destroy an object created with New, use the Dispose command:
' Destroy the point
DISPOSE p2
You can define an initializer for a class by including a NEW method in the class:
' create a Point class
CLASS Point
DIM x, y
SUB NEW ( useX, useY )
x, y = useX, useY
END SUB
END CLASS
' create a Point
p1 = Point( 10, 20 )
When an object is destroyed, the FINALIZE routine for it is run:
' create a Point class
CLASS Point
DIM x, y
SUB NEW ( useX, useY )
x, y = useX, useY
PRINT "Created Point {"; x; ", "; y; ")"
END SUB
SUB FINALIZE()
PRINT "Destroyed the point {"; x; ", "; y; ")"
END SUB
END CLASS