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

4. Default Superclass

All defined classes, if created as a superclass (With no specified parent class) will actually inherit from a special superclass stored in eieio-default-superclass. This superclass is actually quite simple, but with it, certain default methods or attributes can be added to all objects at any time, without updating their code in the future (If there is a change). In CLOS, this would be named STANDARD-CLASS and is aliased.

Currently, the default superclass is defined as follows:

(defclass eieio-default-superclass nil
 "Default class used as parent class for superclasses.  It's
slots are automatically adopted by such superclasses but not stored
in the `parent' slot.  When searching for attributes or methods, when
the last parent is found, the search will recurse to this class.")

When creating an object of any type, you can use it's constructor, or make-instance. This, in turns calls the method initialize-instance, which then calls the method shared-initialize.

Function: initialize-instance obj &rest slots
Initialize obj. Sets slots of obj with slots which is a list of name/value pairs. These are actually just passed to shared-initialize.

Function: shared-initialize obj &rest slots
Sets slots of obj with slots which is a list of name/value pairs.

These methods are used to override errors:

Function: slot-missing object slot operation &optional new-value
This method is called when there is an attempt to access a slot that does not exist for a given object. The default method signals an error of type invalid-slot-name. See section 11. Signals.

You may override this behavior, but it is not expected to return in the current implementation.

This function takes arguments in a different order than in CLOS.

Function: slot-unbound object class slot-name fn
This method is called when there is an attempt to access a slot that is not bound. This will throw an unbound-slot signal. If overridden it's return value will be returned from the function attempting to reference its value.

Function: no-applicable-method object method
This method is called when there is an attempt to call a method on object when there is no method to call. The default method throws a no-method-definition signal. The return value of this function becomes the return value of the non-existent method.

Function: no-next-method object args
This method is called when an attempt to call call-next-method is made, and there is no next method that can be called. The return value becomes the return value of call-next-method.

Additional useful methods are:

Function: clone obj &rest params
Make a deep copy of obj. Once this copy is made, make modifications specified by params. params uses the same format as the slots of initialize-instance. The only other change is to modify the name with an incrementing numeric.

Function: object-print obj &rest strings
Construct a printing lisp symbol for OBJ. This would look like:
 #<class-name "objname">
STRINGS are additional parameters passed in by overloading functions to add more data into the printing abbreviation.

(defclass data-object ()
   "Object containing one data slot.")

(defmethod object-print ((this data-object) &optional strings)
  "Return a string with a summary of the data object as part of the name."
  (apply 'call-next-method this 
	 (cons (format " value: %s" (render this)) strings)))

here is what some output could look like:

(object-print test-object)
   => #<data-object test-object value: 3>

Function: object-write obj &optional comment
Write obj onto a stream in a readable fashion. The resulting output will be lisp code which can be used with read and eval to recover the object. Only slots with :initargs are written to the stream.

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

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html