Next: Object Example
Up: PLT MzScheme: Language Manual
Previous: Structure Utilities
A MzScheme class specifies
- a collection of instance variables,
- initial value expressions for the instance variables, and
- initialization variables that are bound to initialization
arguments.
An object is a collection of bindings for instance variables
that are instantiated according to a class description. There is no
distinction between ``methods'' and ``instance variables''; a method
is simply an instance variable with a procedural value.
The core feature of the object system is the ability to define a new
class (a derived class) in terms of an existing class (the
superclass) using inheritance and overriding:
- inheritance: An object of a derived class instantiates
variables declared by the derived class's superclass as well as
variables declared in the derived class expression.
- overriding: A variable declared in a superclass can
be redeclared in the derived class. References to the overridden variable
in the superclass use the binding of the derived class's declaration.
An interface is a collection of variable names that could be
declared by a class. A class implements an interface when it
- declares (or inherits) a public instance variable for each
variable in the interface; and
- specifically declares its intention to implement the interface.
A single class can implement any number of interfaces. A derived
class automatically implements any interface that its superclass
implements.
A new interface can extend one or more interfaces with
additional variables; classes that implement the extended interface
also implement the original interfaces.
Classes, objects, and interfaces are all first-class Scheme
values. However, a MzScheme class or interface is not a MzScheme
object (i.e., there are no ``meta-classes'' or ``meta-interfaces'').
PLT