Classes and Inheritance



next up previous contents index
Next: Modules Up: Overview of the Previous: Specifications

Classes and Inheritance

A type is implemented by one or more _classes_ (10.4). A class contains some instance variables that store the state of objects of the type, and routines that implement the object's methods. The class can also contain implementations of ``private'' methods that are not available to external code that uses its objects.

A class can inherit from a single superclass (10.5). Objects of a subclass contain superclass instance variables and methods. Superclass methods can be renamed in the subclass. Code within a subclass cannot access the inherited instance variables directly; instead, superclass methods are used to access these variables.

A class definition indicates whether subclasses are permitted, and if so, what methods and associated routines they can use (10.4). A special kind of operator called a _maker_ must be exported so that subclasses can initialize the inherited instance variables (10.5.2); in addition private methods can be exported, and public methods can be hidden (10.5.1). This mechanism allows users to provide a rich interface for subclasses, while ensuring that subclasses cannot damage superclass objects (10.5.4).



theta-questions@lcs.mit.edu