Chapter 9
Sealing
Declaring Characteristics of Classes
A class definition may include the
adjectives sealed
, open
, primary
, free
, abstract
,
or concrete
. These adjectives declare characteristics of
the class.
Additional restrictions on the ability to subclass classes may be imposed by define
sealed domain
.
- An explicitly defined class can be declared to be either
sealed or open. If a class is sealed then no additional direct
subclasses other than those explicitly known in the same library may be created. Thus, it
is an error to define a direct subclass of a sealed class in some library other than the
one that defined the sealed class, or to use
make
of<class>
with a sealed class included in the direct superclasses specified by thesuperclasses:
initialization argument. An open class does not prohibit such operations.
When explicitly defining a class, the default is for the class to be sealed. This may be overriden by explicitly specifying that it is open. A class created usingmake
of<class>
is open. There is no specified way to create a sealed class usingmake
. - An explicitly defined class may be declared to be either primary or free. The default is free. Each primary superclass of a class must be either a subclass or a superclass of all the other primary superclasses of the class. (This essentially restricts primary classes to forming a single inheritance chain.) Slots defined in a primary class may be accessed more efficiently than slots defined in a free class.
- An explicitly defined class may be defined to be either abstract or
concrete. The default is concrete. The superclasses of an abstract class must be
abstract. The default method on
make
will signal an error if passed an abstract class. For an abstract class to be instantiable, it must define a method onmake
that delegates to a concrete subclass.