Deriving classes from two, both derived from one same class

Discussion of Common Lisp
Post Reply
Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Deriving classes from two, both derived from one same class

Post by Jasper » Sat May 01, 2010 6:51 am

  • Person A makes defclass class-A
  • Person B does defclass class-B (class-A)
  • Now person adds something: defclass class-A+ (class-A)
  • Person C wants his class-C, but he wasn't stuff from class-A+ and class-B, will defclass class-C (class-B class-A+) work properly, only including A once?
If not, could person A have done instead defclass class-A-pre+ (), class-A+ (class-A class-A-pre+), and then C could do defclass class-C (class-A-pre+ class-B), but this has problems; why not make person B do this pre-thing, and do methods behave properly to allow this pre- stuff. Further, people shouldn't be forced to change what they did in the past to be able to do something in the future.

This has kindah irked me a bunch in using classes.

One could take another approach at classes, seeing changes of these as functions. B= A Badds, A+ = A A+adds, C wants C=A Badds A+adds, maybe classes should have been the variables, and one would derive from a class by making a 'class-function'(the adds) and operating on it. I don't know enough category theory.. Were CLOS/metaobject makers (sufficiently) cognizant category theory?

On the other hand, if defclass class-C (class-B class-A+) works just properly and produces no wtfs then there is no problem.

Edit: Reading this there shouldn't be a problem with this specifically; everything derives from standard-object already.

However, what of the problem when you want to features of two, but not to copy of the data contained.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Deriving classes from two, both derived from one same class

Post by gugamilare » Sat May 01, 2010 8:33 am

Jasper wrote:
  • Person A makes defclass class-A
  • Person B does defclass class-B (class-A)
  • Now person adds something: defclass class-A+ (class-A)
  • Person C wants his class-C, but he wasn't stuff from class-A+ and class-B, will defclass class-C (class-B class-A+) work properly, only including A once?
[...]
AFAIK there is no way to include a class twice, so, yes, it will include the class A only once.
Jasper wrote:Edit: Reading this there shouldn't be a problem with this specifically; everything derives from standard-object already.

However, what of the problem when you want to features of two, but not to copy of the data contained.
You mean making the class-C not to have some specific slots from class-A or class-B? I'm not sure. You can make a slot which has :allocation :instance on class-A to have :allocation :class on class-C, you can to create new readers and writers for each slot or change their initforms. Removing slots, though, I believe it's only possible using MOP.

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: Deriving classes from two, both derived from one same class

Post by Jasper » Sat May 01, 2010 6:27 pm

Ok, good to know you can do what C wants that way.
gugamilare wrote:You mean making the class-C not to have some specific slots from class-A or class-B?
Actually i meant that A has some generic functions, and both B and A+ override it for their classes. Then one might want to be able to use both the method for B and A+, but the precidence will always turn out to be one of the two.

I also noticed another thing. I was working on a little dependency-system, much like i suggested here, but instead with functions in special variables instead of methods. Anyway, compile/loading needs to keep a state, and i also wanted testing to keep a state. I was tempted to just derive the test state class from the compile/loading state class, and then just change-class to add the data on testing state.(particularly the last time it was tested, the last time the test was compiled/loaded is done via regular compiling/loading.) However this is a slippery slope, i might be tempted to do the same thing with some other action, and then change-class wouldn't be able to figure out what to do. It'd be somewhat analogous to doing change-class from B to A+.

I guess classes can be fairly treaturous, things often have to be slots, or (more rarely)some other way to find the data instead.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Deriving classes from two, both derived from one same class

Post by nuntius » Sat May 01, 2010 9:28 pm

Take a look at ContextL for a handful of tricks that may help.

dlweinreb
Posts: 41
Joined: Tue Jul 01, 2008 5:11 am
Location: Lexington, MA
Contact:

Re: Deriving classes from two, both derived from one same class

Post by dlweinreb » Sat May 08, 2010 9:21 am

Yes, it's OK for C to inherit from both A+ and B. He will not "get A twice". He will only get A once.

This scenario is usually known as the "diamond pattern", by the way, because of the shape that you get when you diagram it.

Now, if all these guys define a method called "m", you will have to know about the flattening of the hierarchy. CLOS
has rules for that.

Post Reply