Re: [CLOS] Ensuring a method exists



Didier Verna <didier@xxxxxxxxxxxxx> writes:

Rahul Jain <rjain@xxxxxxxx> wrote:

You shouldn't be subclassing something if you don't want to get its
functionality as default.

Sorry ? Consider the classic binary method example Point <- ColorPoint with
the point= function. ColorPoint *is* a subclass of Point, and *no*, I don't
want the implementation of point= for Point as the default functionality in
ColorPoint. I want to be sure that there is an implementation of point= for
both classes.

Equality is not an OO concept. You should not be using a g-f to
determine equality. What would it mean for me to compare a point to a
color-point? And I mean OO in the polymorphic sense, not the
encapsulation sense.

Acutally, if I created a point= operator, I would want a point and a
color-point to be compared on coordinates only, disregarding the color
of the color-point, so I _would_ want the funcitonality to be inherited,
but NEVER overridden. So I'd just write a function for point= and allow
the polymorphism to apply at the level of pulling the coords out of the
object. I'd write a color-point-equal function to compare the coords and
colors.

There's a reason why the equality operators in CL are not g-fs.

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.

How much control do you have on the time at which the check is
performed ?

You call it explicitly. Total control. Total responsibility. Of course,
this is necessary in a dynamic lanaguage, because the "validity" of the
code according to some criteria changes as definitons are added,
modified, and removed from the system.

It won't help you with trying to change the way the applicable method
list is computed, tho. It just checks that there exists an applicable
method. It's also not going to inspect the code of each method to make
sure that every time it calls call-next-method, there will be a next
method to call. Not sure I could do that in a way that avoids false
negatives anyway.

--
Rahul Jain
rjain@xxxxxxxx
Professional Software Developer, Amateur Quantum Mechanicist
.