Re: [CLOS] Ensuring a method exists
- From: Ken Tilton <kentilton@xxxxxxxxx>
- Date: Wed, 27 Sep 2006 08:11:43 -0400
Christophe Rhodes wrote:
Ken Tilton <kentilton@xxxxxxxxx> writes:
Of course the big question no one will ask is why you want to do
this. Sounds like bad design. But you are not alone, we get people
wanting to do this almost as often as we get people trying to fix the
parens.
I'm not so certain that this kind of thing is necessarily bad design.
I think that CLOS's generic functions and class inheritance provide
good ways of adding functionality ("extending", if you will) by
subclassing; what I think is harder to express in vanilla CLOS is
removal of invariants, or generalization of functionality.
To take a concrete example, consider implementing a data structure
such as an R-tree, which has a relatively complex set of invariants
that you might want to assert are true at various points in the
protocol. Then you implement a variant, such as the R*-tree, which
obeys the same protocol, and indeed shares much of the implementation,
but has slightly different (but overlapping) invariants. How do you
model that, with just CLOS? Probably what you do is define some kind
of abstract base class and make R-trees and R*-trees inherit from that
base class, but now you can't share the methods that actually should
be shared:
Oh. Why not? Don't see that from the set-up above. And, whatever it is, multiple-inheritance won't help? If not, sounds like classes and the very idea of OO are simply the wrong hammer for this problem, and it might be wiser to byte the bullet and use macrology and the DSL thing to Just Say What We Mean.
Now maybe that is what is going on and the OP is just leveraging CLOS as a convenient internal tool to the larger API, but then that is why I suggest going /further/ and hide the CLOS behind some macrology, at which point the OP can enforce anything they want really really easily (instead of staring at AMOP looking for support for something not really OO-able).
instead you have to implement the methods separately,
admittedly maybe with a call to the same function. So sometimes I
think it makes sense to want to treat direct instances and general
instances of a class differently: it allows you to express things in a
way that is closer to the application space (which is what we're
aiming for, right?)
Well, I'm not smart like you guys, I can only think in concrete, so I kinda would have to see the actual use case.*
kt
* I get a kick out of it when people respond "oh, sure. here ya go. there's this class foo, see, and this other class bar, and...". :) k
--
Cells: http://common-lisp.net/project/cells/
"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
.
- Follow-Ups:
- Re: [CLOS] Ensuring a method exists
- From: Pascal Costanza
- Re: [CLOS] Ensuring a method exists
- From: Christophe Rhodes
- Re: [CLOS] Ensuring a method exists
- References:
- [CLOS] Ensuring a method exists
- From: Didier Verna
- Re: [CLOS] Ensuring a method exists
- From: Lars Rune Nøstdal
- Re: [CLOS] Ensuring a method exists
- From: Didier Verna
- Re: [CLOS] Ensuring a method exists
- From: Ken Tilton
- Re: [CLOS] Ensuring a method exists
- From: Christophe Rhodes
- [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
|
|