www.delorie.com/gnu/docs/guile/goops_41.html   search  
Buy GNU books!

Goops Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9 Changing the Class of an Instance

You can change the class of an existing instance by invoking the generic function change-class with two arguments: the instance and the new class.

generic: change-class

The default method for change-class decides how to implement the change of class by looking at the slot definitions for the instance's existing class and for the new class. If the new class has slots with the same name as slots in the existing class, the values for those slots are preserved. Slots that are present only in the existing class are discarded. Slots that are present only in the new class are initialized using the corresponding slot definition's init function (see section slot-init-function).

method: change-class (obj <object>) (new <class>)
Modify instance obj to make it an instance of class new.

The value of each of obj's slots is preserved only if a similarly named slot exists in new; any other slot values are discarded.

The slots in new that do not correspond to any of obj's pre-existing slots are initialized according to new's slot definitions' init functions.

Customized change of class behaviour can be implemented by defining change-class methods that are specialized either by the class of the instances to be modified or by the metaclass of the new class.

When a class is redefined (see section 3.8 Redefining a Class), and the default class redefinition behaviour is not overridden, GOOPS (eventually) invokes the change-class generic function for each existing instance of the redefined class.

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003