Re: [CLOS] Ensuring a method exists
- From: Rahul Jain <rjain@xxxxxxxx>
- Date: Tue, 03 Oct 2006 14:23:17 -0400
Didier Verna <didier@xxxxxxxxxxxxx> writes:
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).
RED FLAG!
You shouldn't be subclassing something if you don't want to get its
functionality as default. You shouldn't be using subclassing at all
here. I suspect that if you use my library do define a protocol like
VALIDATABLE and have method on the VALIDATE g-f as part of the protocol,
you'll get what you want. Then VALIDATABLE wouldn't be a class, so you
wouldn't get any functionality from it, just the requirement of that
method being implemented for VALIDATABLE classes.
So maybe you're just using the wrong terminology, as you haven't been
exposed to the Lisp concept of "protocols" which are analgous to the
Java concept of "interfaces" except that protocols aren't part of the
language officially (as it's rather tricky to force anything to be
around before anything else in a multiple-dispatch, dynamic OO
language). My library just allows a declaration of what a class
conforming to a protocol should support and a function to test whether
it has gotten to that point after you've loaded all appropriate code.
Note that in CL, you can add functionality to a class in a different
library. Think about dispatching on INTEGER; effectively, you've now
given the INTEGER class more functionality than it may have before. This
is why my library allows you to declare protocols both inside the
defclass form as well as outside (to parallel the method definitions
that can occur in both places, as well).
--
Rahul Jain
rjain@xxxxxxxx
Professional Software Developer, Amateur Quantum Mechanicist
.
- Follow-Ups:
- Re: [CLOS] Ensuring a method exists
- From: Didier Verna
- Re: [CLOS] Ensuring a method exists
- Prev by Date: Re: [CLOS] Ensuring a method exists
- Next by Date: Re: [CLOS] Ensuring a method exists
- Previous by thread: Re: [CLOS] Ensuring a method exists
- Next by thread: Re: [CLOS] Ensuring a method exists
- Index(es):
Relevant Pages
|