Next: , Previous: Initialization, Up: Default Superclass

15.2 Basic Methods

Additional useful methods defined on the base subclass are:

— Function: clone obj &rest params

Make a copy of obj, and then apply params. params is a parameter list of the same form as initialize-instance which are applied to change the object. When overloading clone, be sure to call cl-call-next-method first and modify the returned object.

— Function: object-print this &rest strings

Pretty printer for object this. Call function eieio-object-name with strings. The default method for printing object this is to use the function eieio-object-name.

It is sometimes useful to put a summary of the object into the default #<notation> string when using eieio browsing tools.

Implement this function and specify strings in a call to cl-call-next-method to provide additional summary information. When passing in extra strings from child classes, always remember to prepend a space.

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

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.