When define-class
notices that a class is being redefined, it
constructs the new class metaobject as usual, then invokes the
class-redefinition
generic function with the old and new classes
as arguments. Therefore, if the old or new classes have metaclasses
other than the default <redefinable-class>
, class redefinition
behavior can be customized by defining a class-redefinition
method that is specialized for the relevant metaclasses.
Handle the class redefinition from old to new, and return
the new class metaobject that should be bound to the variable specified
by define-class
’s first argument.
Not all classes are redefinable, and not all previous bindings are classes. See Redefinable Classes. This default method just returns new.
This method implements GOOPS’ default class redefinition behavior, as described in Default Class Redefinition Behavior. Returns the metaobject for the new class definition.
The class-redefinition
method for classes with metaclass
<redefinable-class>
calls the following generic functions, which
could of course be individually customized.
The default remove-class-accessors!
method removes the accessor
methods of the old class from all classes which they specialize.
The default update-direct-method!
method substitutes the new
class for the old in all methods specialized to the old class.
The default update-direct-subclass!
method invokes
class-redefinition
recursively to handle the redefinition of
subclasses.
An alternative class redefinition strategy could be to leave all existing instances as instances of the old class, but accepting that the old class is now “nameless”, since its name has been taken over by the new definition. In this strategy, any existing subclasses could also be left as they are, on the understanding that they inherit from a nameless superclass.
This strategy is easily implemented in GOOPS, by defining a new metaclass,
that will be used as the metaclass for all classes to which the strategy
should apply, and then defining a class-redefinition
method that
is specialized for this metaclass:
(define-class <can-be-nameless> (<redefinable-class>)) (define-method (class-redefinition (old <can-be-nameless>) (new <class>)) new)
When customization can be as easy as this, aren’t you glad that GOOPS implements the far more difficult strategy as its default!