Next: Object Example Up: PLT MzScheme: Language Manual Previous: Structure Utilities

# Classes and Objects

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

- 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 instance variable names to be implemented by a class, combined with a derivation requirement for the class. A class implements an interface when it

- declares (or inherits) a public instance variable for each variable in the interface;
- is derived from the class required by the interface, if any; and
- specifically declares its intention to implement the interface.

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'').

- Object Example
- Creating Interfaces
- Creating Classes
  - Initialization Variables
  - Instance Variables
  - Initial Values
- Creating Objects
- Instance Variable Access
  - Generic Procedures
- Object Utilities

Next: Object Example Up: PLT MzScheme: Language Manual Previous: Structure Utilities