Re: [CLOS] Ensuring a method exists



Lars Rune Nøstdal <larsnostdal@xxxxxxxxx> wrote:

This seems to work:

(defclass SomeBase ()
())


(defmethod initialize-instance :before ((some-base SomeBase) &key)
(format t "Checking for `foo': ~A~%"
(find-method #'foo '() (mapcar #'find-class
(list (type-of some-base)
(type-of some-base))))))


(defmethod foo ((a SomeBase) (b SomeBase))
(write-line "(foo SomeBase SomeBase)"))


(defclass SomeDerived (SomeBase)
())


That's a nice solution but it has one caveat (my question was probably
not clear enough about this): your trick checks for the existence of a method
only for the class you instanciate, and not for the subclasses.

So imagine having A <- B and creating only instances of B. The lack of method
for class A would go unnoticed. But I want the check for the whole hierarchy
(consider for instance that I'm using the AND method combination type and I'm
expecting an implementation for all the classes).

--
Check out my new jazz CD on http://www.didierverna.com/ !

Didier Verna EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bicêtre, France Fax.+33 (1) 53 14 59 22
.



Relevant Pages