[previous] [up] [next]     [index]
Next: Object Example Up: PLT MzScheme: Language Manual Previous: Structure Utilities

Classes and Objects

A MzScheme class specifies

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 merely 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:

An interface is a collection of instance variable names to be implemented by a class, combined with a derivation requirement for the class. A class implements an interface when it

A class can implement any number of interfaces. A derived class automatically implements any interface that its superclass implements. Each class also implements an implicitly-defined interface that is associated with the class. The implicitly-defined interface contains all of the class's instance variables, and it requires that all other implementations of the interface are derived from the class.

A new interface can extend one or more interfaces with additional variables; each class that implements the extended interface also implements the original interfaces. The derivation requirements of the original interface must be consistent, and the extended interface inherits the most specific derivation requirement from 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'').




[previous] [up] [next]     [index]
Next: Object Example Up: PLT MzScheme: Language Manual Previous: Structure Utilities

PLT