From: Ralph Richard Cook
Subject: Multimethods vs. Multiple Inheritance/Mixins
Date: 
Message-ID: <40dba4b9.13714900@newsgroups.bellsouth.net>
I'm about to come across my own version of the classic problem where I
have different types of data and I will want to draw or render the
data different ways. 

In Common Lisp the obvious way seems to be to have two separate class
hierarchies and have them come together with multimethods, as shown at
http://www.norvig.com/design-patterns/ppframe.htm, slide 23.
You have a "draw" method, and pass in your data-holding object and
your graphics object.

However, David Lamkins in "Successful Lisp"
http://www.psg.com/~dlamkins/sl/chapter07.html
combines the two class hierarchies with mixins and has his "draw"
methods take one mixed-in object. The data-munging and drawing method
hierarchies are kept seperate, and inside the "draw" method you make
two calls, one to the data-munging method "transfer", then to the
drawing method "render".

It seems to me that the multimethod way would be cleaner, especially
when viewing the spider-web class hierarchy diagram in chapter 7, but
I'm still getting in a Lisp mindset and hey, I've been wrong before so
I'd like to get some advice on this from Lispers that have more
experience with multiple dispatch.

Thanks

From: Kenny Tilton
Subject: Re: Multimethods vs. Multiple Inheritance/Mixins
Date: 
Message-ID: <FvXCc.25$oW6.68248@twister.nyc.rr.com>
Ralph Richard Cook wrote:

> I'm about to come across my own version of the classic problem where I
> have different types of data and I will want to draw or render the
> data different ways. 
> 
> In Common Lisp the obvious way seems to be to have two separate class
> hierarchies and have them come together with multimethods, as shown at
> http://www.norvig.com/design-patterns/ppframe.htm, slide 23.
> You have a "draw" method, and pass in your data-holding object and
> your graphics object.
> 
> However, David Lamkins in "Successful Lisp"
> http://www.psg.com/~dlamkins/sl/chapter07.html
> combines the two class hierarchies with mixins and has his "draw"
> methods take one mixed-in object. The data-munging and drawing method
> hierarchies are kept seperate, and inside the "draw" method you make
> two calls, one to the data-munging method "transfer", then to the
> drawing method "render".
> 
> It seems to me that the multimethod way would be cleaner, especially
> when viewing the spider-web class hierarchy diagram in chapter 7, but
> I'm still getting in a Lisp mindset and hey, I've been wrong before so
> I'd like to get some advice on this from Lispers that have more
> experience with multiple dispatch.

I settled on hybrid approach after some experimentation.

First of all, yeah, separate hierarchies for model and view (and focus 
management and control (button, slider) capabilities and...).

Then I settled on the view class having a "value" slot for a model 
instance of which it provides a view. The view instance gets whatever 
info it needs from the model instance, which knows nothing about the 
view. I have seen this pattern a few other places.

I tried having one class inherit from both a model and view class, but I 
hated it.

kt

-- 
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
From: Rahul Jain
Subject: Re: Multimethods vs. Multiple Inheritance/Mixins
Date: 
Message-ID: <87659elzkl.fsf@nyct.net>
······@bellsouth.net (Ralph Richard Cook) writes:

> However, David Lamkins in "Successful Lisp"
> http://www.psg.com/~dlamkins/sl/chapter07.html
> combines the two class hierarchies with mixins and has his "draw"
> methods take one mixed-in object. The data-munging and drawing method
> hierarchies are kept seperate, and inside the "draw" method you make
> two calls, one to the data-munging method "transfer", then to the
> drawing method "render".

You can't have the same object being drawn on different media with this
approach.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Ralph Richard Cook
Subject: Re: Multimethods vs. Multiple Inheritance/Mixins
Date: 
Message-ID: <40de343b.6370360@newsgroups.bellsouth.net>
Looks like you're right - the Lamkins way the data and rendering are
wedded (welded?) together, making it harder to re-use the data and
render it in different ways, something I'll want to do since building
the data can be expensive.


Rahul Jain <·····@nyct.net> wrote:

>······@bellsouth.net (Ralph Richard Cook) writes:
>
>> However, David Lamkins in "Successful Lisp"
>> http://www.psg.com/~dlamkins/sl/chapter07.html
>> combines the two class hierarchies with mixins and has his "draw"
>> methods take one mixed-in object. The data-munging and drawing method
>> hierarchies are kept seperate, and inside the "draw" method you make
>> two calls, one to the data-munging method "transfer", then to the
>> drawing method "render".
>
>You can't have the same object being drawn on different media with this
>approach.