All Manuals > LispWorks User Guide and Reference Manual > 14 The Metaobject Protocol > 14.2 Common problems when using the MOP

NextPrevUpTopContentsIndex

14.2.1 Inheritance across metaclasses

Usually an inherited class is of the same metaclass as the parent class.

For other kinds of inheritance, you need to define a method on validate-superclass which returns true when called with the respective metaclasses. For example:

(defclass mclass-1 (standard-class)
  ())
 
(defclass mclass-2 (standard-class)
  ())
 
(defclass a ()
  ()
  (:metaclass mclass-1))
 
(defmethod validate-superclass 
           ((class mclass-2) 
            (superclass mclass-1)) 
  t)
 
(defclass b (a)
  ()
  (:metaclass mclass-2))

Without the validate-superclass method, the last form signals an error because mclass-1 is an invalid superclass of mclass-2 .


LispWorks User Guide and Reference Manual - 21 Dec 2011

NextPrevUpTopContentsIndex