Re: Is it possible to remove a slot when inheriting?



On May 15, 8:16 pm, Joe Marshall <eval.ap...@xxxxxxxxx> wrote:
On May 15, 7:24 am, Pedro Kroger <pedro.kro...@xxxxxxxxx> wrote:



Hi,

suppose I have a class with 6 slots, is it possible to inherit that
class except for one slot? for instance, if I have foo like this:

(defclass foo ()
(a1 a2 a3 a5 a5 a6))

and bar is a subclass of foo:

(defclass bar (foo)
...)

foo will have, of course, the 6 slots, but I want bar to have all
slots of foo except a6. I don't have any specific use for this, I'm
just thinking if this is possible or not. (I don't even know if this
is good practice)

This is an instance of `subtractive inheritance'. CLOS doesn't
support it by default (but you can always change that).

It's probably not a good idea because if BAR inherits from FOO, then a
BAR object should be usable as a FOO. If the BAR object doesn't have
an a6 slot, then it is likely to not work for certain methods.

Consider a rectangle inheriting from polygon. You want to keep a list
of points in polygon, but you want width/height, x/y slots in
rectangle. You define an accessor method `points` that computes the
list of points for rectangles.

Jules

.



Relevant Pages

  • Re: Do I *have* to use OOP to use modules?
    ... Sure, Foo lives in a state of sin from an IOO point of view, ... Why will IOO ... And that's how people will learn Perl objects, ... ** to go through contortions to enable full or partial inheritance. ...
    (comp.lang.perl.misc)
  • Re: a case for multiple inheritance
    ... Although C# has Generics, it still does not support the generic ... I need to expose two lists of objects from a high-level class. ... While this usage of inheritance does not conform to the "is-a" relation ... private new void Foo ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: inheritance, yes, but how?
    ... Making class based inheritance in Javascript is hard because Javscript ... var superObj = new Object; ... var foo = new Foo; ... Now, if you understand this, you can see that treating constructors as ...
    (microsoft.public.scripting.jscript)
  • Re: Do I *have* to use OOP to use modules?
    ... "" by anything that isn't compatible with Foo in the usual sense. ... Why will IOO ... to go through contortions to enable full or partial inheritance. ... constructing an object and initializing an object. ...
    (comp.lang.perl.misc)
  • Re: Class inheritance
    ... > class Foo ... > class Bar ... > function FooBar() ... > than inheritance, but it seems to me the effect is close. ...
    (comp.lang.php)