From: Tayssir John Gabbour
Subject: Multiple inheritance examples?
Date: 
Message-ID: <525cf5f9-2e99-4f9b-b06d-fa55a83b62ab@i29g2000prf.googlegroups.com>
Hi!

I'm helping a Java-influenced person learn CLOS concepts. Does anyone
have good examples of multiple inheritance? Ones which aren't too
abstract?

The best ones I can think of come from the GUI world. Like a widget
inheriting from a bordered mixin. Or in LispWorks, you have:

    option-pane's superclasses: choice, titled-object, simple-pane


I use a UUID mixin all the time for unique object identity, as I push
objects through networks or whatever. But I think that's too abstract
for my discussion.


I'm hard-pressed to think of good examples of people. That would be
really nice. Maybe the concept of "person" might be combined with some
security mixin?


Thanks,
Tayssir

From: Peter Hildebrandt
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <47ac238f$0$90263$14726298@news.sunsite.dk>
Tayssir John Gabbour wrote:
> Hi!
> 
> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> have good examples of multiple inheritance? Ones which aren't too
> abstract?

Since you'd like examples with people:

(defclass person ()
   ((name ...)
    (age ...)
    (gender ...)))

and there's students

(defclass student ()
   ((classes ...)
    (GPA ...)))

So you have

(defclass studying-person (person student)
   ())

Ok, you could have defined that one dirfectly, without inheritance.

Now there's employees

(defclass employee ()
   ((employer ...)
    (income ...)))

And thus

(defclass employed-person (person employee)
   ())

Could have done that one w/]o multiple inheritance, too.

But what if you want to represent students who have a job?

With multiple inheritance, you do

(defclass working-student (person student employee)
   ())

Without, you'd have to do something like

(defclass working-student-b (studying-person)
   ((employer ...)
    (income ...)))

Thus duplicating the stuff that's already in employee.  Disadvatages:

- if you change employee, you need to change working-student-b as well
- methods specialising on employed-person don't work on working-student
....

"HTH,
Peter


> The best ones I can think of come from the GUI world. Like a widget
> inheriting from a bordered mixin. Or in LispWorks, you have:
> 
>     option-pane's superclasses: choice, titled-object, simple-pane
> 
> 
> I use a UUID mixin all the time for unique object identity, as I push
> objects through networks or whatever. But I think that's too abstract
> for my discussion.
> 
> 
> I'm hard-pressed to think of good examples of people. That would be
> really nice. Maybe the concept of "person" might be combined with some
> security mixin?
> 
> 
> Thanks,
> Tayssir
From: Pascal Costanza
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <612pltF1ti59lU1@mid.individual.net>
Tayssir John Gabbour wrote:
> Hi!
> 
> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> have good examples of multiple inheritance? Ones which aren't too
> abstract?

Java programmers actually use multiple inheritance more often than they 
are aware of. It's just more clumsy.

Here are some links:
- http://mindprod.com/jgloss/interfacevsabstract.html
- http://c2.com/ppr/wiki/JavaIdioms/BuildInterfaceImplementationPairs.html
- http://citeseer.ist.psu.edu/mohnen02interfaces.html

I know there was a better link for this idea, but I currently don't find 
it...


Pascal

-- 
1st European Lisp Symposium (ELS'08)
http://prog.vub.ac.be/~pcostanza/els08/

My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Pascal Costanza
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <613262F1rcv5cU1@mid.individual.net>
Pascal Costanza wrote:
> Tayssir John Gabbour wrote:
>> Hi!
>>
>> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
>> have good examples of multiple inheritance? Ones which aren't too
>> abstract?
> 
> Java programmers actually use multiple inheritance more often than they 
> are aware of. It's just more clumsy.
> 
> Here are some links:
> - http://mindprod.com/jgloss/interfacevsabstract.html
> - http://c2.com/ppr/wiki/JavaIdioms/BuildInterfaceImplementationPairs.html
> - http://citeseer.ist.psu.edu/mohnen02interfaces.html
> 
> I know there was a better link for this idea, but I currently don't find 
> it...

Basically, there is an idiom which is used in the Swing framework, but 
also elsewhere, where an API is presented in three entities: An 
interface that defines the API as such, an abstract class implementing 
that interface which provides template methods for easy subclassing, and 
a default implementation derived from that abstract class that can just 
be instantiated to get the behavior you 'usually' want.

If you subclass the abstract class, you automatically implement the 
interface, but get the convenience of useful default implementations for 
some aspects of the interface. If you need to be able to subclass a 
different class, you can still implement the interface, but have to 
implement all elements of the interface yourself (for example, by 
forwarding to an instance of the default implementation).

The latter corresponds to a technique sometimes called sibling classes, 
which is a way to manually simulate multiple inheritance. (Forwarding 
can have its own problems, because after forwarding, the 'this' 
reference has changed, so in the most general case you need some form of 
prototype-style delegation to fully simulate multiple inheritance.)

Sibling classes should exist quite often in large Java code bases. Look 
for those (and the above idiom of separating APIs into interface, 
abstract classe and default concrete classes), and you will have good 
examples for multiple inheritance.

Multiple inheritance is typically rejected because of potential 
conflicts between overriding methods. This largely doesn't exist in CLOS 
(although there are some minor remaining cases). However, in languages 
like C++ and Eiffel they do exist. This is mostly because in those 
languages, classes are also used to create namespaces, and you then 
inevitably get name clashes. CLOS doesn't have this problem because the 
handling of namespaces is handed out to the package system.

Since a few years, traits were developed (mostly in the Smalltalk 
community, but picked up elsewhere as well, for example in Fortress), 
which separates classes from mixins and thus gives you some way of 
better controlling such conflicts. It's essentially a variation on 
"interfaces with default implementations", which are copied into 
implementing classes unless they provide their own definitions. Traits 
seem to make multiple inheritance somewhat more palatable to a general 
audience, but the problems they solve are not pressing enough IMHO. 
Traits also still seem to have some problems with multiple dispatch...


Pascal

-- 
1st European Lisp Symposium (ELS'08)
http://prog.vub.ac.be/~pcostanza/els08/

My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Andrew Reilly
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <612tj2F1svdsjU2@mid.individual.net>
On Fri, 08 Feb 2008 01:13:27 -0800, Tayssir John Gabbour wrote:

> I'm hard-pressed to think of good examples of people. That would be
> really nice. Maybe the concept of "person" might be combined with some
> security mixin?

Not CLOS, but Bertrand Meyer's "Object Oriented Software Construction" 
has lots of good examples of multiple inheritance.  No multiple dispatch, 
either (since Eiffel is single-dispatch, method style OO), but that 
should be a gentle intro for your Java friend.

A while since I've read it, I'm afraid, so I can't remember any exmaples 
here.  I just remember thinking that it was good, at the time.

Cheers,

-- 
Andrew
From: Pascal J. Bourguignon
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <7codarr1e5.fsf@pbourguignon.anevia.com>
Tayssir John Gabbour <············@googlemail.com> writes:

> Hi!
>
> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> have good examples of multiple inheritance? Ones which aren't too
> abstract?

I've used multiple inheritance in:

http://darcs.informatimago.com/lisp/common-lisp/source-text.lisp
(see macro-character-mixin etc)

http://darcs.informatimago.com/lisp/common-lisp/source-form.lisp
(see the various lambda-list classes, like ordinary-lambda-list)


Are lisp notions applied to lisp notions too abstract?  For a java programmer, perhaps.


> The best ones I can think of come from the GUI world. Like a widget
> inheriting from a bordered mixin. Or in LispWorks, you have:

GUI is a domain where OO excels, yes.

-- 
__Pascal Bourguignon__
From: Victor Kryukov
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <87sl022boa.fsf@esculap.gateway.2wire.net>
Tayssir John Gabbour <············@googlemail.com> writes:

> Hi!
>
> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> have good examples of multiple inheritance? Ones which aren't too
> abstract?
>
> The best ones I can think of come from the GUI world. Like a widget
> inheriting from a bordered mixin. Or in LispWorks, you have:
>
>     option-pane's superclasses: choice, titled-object, simple-pane
>
>
> I use a UUID mixin all the time for unique object identity, as I push
> objects through networks or whatever. But I think that's too abstract
> for my discussion.
>
>
> I'm hard-pressed to think of good examples of people. That would be
> really nice. Maybe the concept of "person" might be combined with some
> security mixin?

You may also want to check "Object-Oriented Programming in Common
Lisp" by Sonja E. Keene, which provides a nice introduction into
CLOS. It has an example of locking system in chapter 3, which uses
multiple inheritance in a form of an ordered-lock-mixin which adds the
ability to identify/resolve deadlock situations to base classes like
null-lock and simple-lock.

So you have

(defclass ordered-lock (ordered-lock-mixin simple-lock)
  ...)

and

(defclass ordered-null-lock (ordered-lock-mixin null-lock)
  ...)

Regards,
Victor.
From: Rainer Joswig
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <joswig-BBB732.20544009022008@news-europe.giganews.com>
In article <··············@esculap.gateway.2wire.net>,
 Victor Kryukov <··············@gmail.com> wrote:

> Tayssir John Gabbour <············@googlemail.com> writes:
> 
> > Hi!
> >
> > I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> > have good examples of multiple inheritance? Ones which aren't too
> > abstract?
> >
> > The best ones I can think of come from the GUI world. Like a widget
> > inheriting from a bordered mixin. Or in LispWorks, you have:
> >
> >     option-pane's superclasses: choice, titled-object, simple-pane
> >
> >
> > I use a UUID mixin all the time for unique object identity, as I push
> > objects through networks or whatever. But I think that's too abstract
> > for my discussion.
> >
> >
> > I'm hard-pressed to think of good examples of people. That would be
> > really nice. Maybe the concept of "person" might be combined with some
> > security mixin?
> 
> You may also want to check "Object-Oriented Programming in Common
> Lisp" by Sonja E. Keene, which provides a nice introduction into
> CLOS. It has an example of locking system in chapter 3, which uses
> multiple inheritance in a form of an ordered-lock-mixin which adds the
> ability to identify/resolve deadlock situations to base classes like
> null-lock and simple-lock.
> 
> So you have
> 
> (defclass ordered-lock (ordered-lock-mixin simple-lock)
>   ...)
> 
> and
> 
> (defclass ordered-null-lock (ordered-lock-mixin null-lock)
>   ...)
> 
> Regards,
> Victor.

Or streams.

A bidirectional-stream inherits from input-stream and output-stream .
From: Thomas F. Burdick
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <f6dfac56-fe38-4927-abed-8ed81e8de9b2@p69g2000hsa.googlegroups.com>
On Feb 8, 10:13 am, Tayssir John Gabbour <············@googlemail.com>
wrote:
> Hi!
>
> I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> have good examples of multiple inheritance? Ones which aren't too
> abstract?
>
> The best ones I can think of come from the GUI world. Like a widget
> inheriting from a bordered mixin. Or in LispWorks, you have:
>
>     option-pane's superclasses: choice, titled-object, simple-pane
>
> I use a UUID mixin all the time for unique object identity, as I push
> objects through networks or whatever. But I think that's too abstract
> for my discussion.
>
> I'm hard-pressed to think of good examples of people. That would be
> really nice. Maybe the concept of "person" might be combined with some
> security mixin?

I don't think you will come up with any easy, pithy examples that
don't break is-a relationships and don't come off as looking like more
trouble than they're worth.  There's a reason why single-inheritance
languages are as successful as they are; most of the time you only
need SI, and in quite a lot of cases where you'd like to have MI,
working around SI is so little of an imposition that arguing for the
added complexity (to the language) of MI isn't a clear win.  In the
remaining cases it's great, and saves you quite a bit of complexity in
your program.  However, much like other relatively advanced
techniques, like e.g. compiling to a network of closures, I don't know
that you'll find a convincing one-page example, for the simple reason
that if the problem is that small there's not much room for savings.

Pascal gave you some leads on how Java programmers try to mimic MI,
which is IMO the right path.  That way you can leverage the large
problem these Java guys already have in their head and show them how
the solution would be simpler with MI.  Just be sure to pick an
example where it *is* simpler :-)
From: Ken Tilton
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <47b021aa$0$25017$607ed4bc@cv.net>
Thomas F. Burdick wrote:
> On Feb 8, 10:13 am, Tayssir John Gabbour <············@googlemail.com>
> wrote:
> 
>>Hi!
>>
>>I'm helping a Java-influenced person learn CLOS concepts. Does anyone
>>have good examples of multiple inheritance? Ones which aren't too
>>abstract?
>>
>>The best ones I can think of come from the GUI world. Like a widget
>>inheriting from a bordered mixin. Or in LispWorks, you have:
>>
>>    option-pane's superclasses: choice, titled-object, simple-pane
>>
>>I use a UUID mixin all the time for unique object identity, as I push
>>objects through networks or whatever. But I think that's too abstract
>>for my discussion.
>>
>>I'm hard-pressed to think of good examples of people. That would be
>>really nice. Maybe the concept of "person" might be combined with some
>>security mixin?
> 
> 
> I don't think you will come up with any easy, pithy examples that
> don't break is-a relationships and don't come off as looking like more
> trouble than they're worth. 

Nonsense! Hell, I did multiple inheritance with /metaclasses/, combining 
Cells and AllegroStore metaclasses to create databases that were alive, 
one change to the DB rippling out across the DB to other entries to keep 
them self-consistent.

[Aside: Try to talk a self-updating database past change control some day.}

Worked like a charm, tho, thanks to multiple inheritance and   two 
metaclasses built to follow the rules.

kenny

ps. If no one needs multiple inheritance, how come everyone else fakes 
it with "interfaces" or dispatching schemes (ST, IIRC). k

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Thomas F. Burdick
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <408a9450-43bf-4095-bc81-7a109fc09f99@h11g2000prf.googlegroups.com>
On Feb 11, 11:21 am, Ken Tilton <···········@optonline.net> wrote:
> Thomas F. Burdick wrote:
> > On Feb 8, 10:13 am, Tayssir John Gabbour <············@googlemail.com>
> > wrote:
>
> >>Hi!
>
> >>I'm helping a Java-influenced person learn CLOS concepts. Does anyone
> >>have good examples of multiple inheritance? Ones which aren't too
> >>abstract?
>
> >>The best ones I can think of come from the GUI world. Like a widget
> >>inheriting from a bordered mixin. Or in LispWorks, you have:
>
> >>    option-pane's superclasses: choice, titled-object, simple-pane
>
> >>I use a UUID mixin all the time for unique object identity, as I push
> >>objects through networks or whatever. But I think that's too abstract
> >>for my discussion.
>
> >>I'm hard-pressed to think of good examples of people. That would be
> >>really nice. Maybe the concept of "person" might be combined with some
> >>security mixin?
>
> > I don't think you will come up with any easy, pithy examples that
> > don't break is-a relationships and don't come off as looking like more
> > trouble than they're worth.
>
> Nonsense!

I have no idea if you're disagreeing with me, or are in violent
agreement or what.  For what it's worth, this :

> Hell, I did multiple inheritance with /metaclasses/, combining
> Cells and AllegroStore metaclasses to create databases that were alive,
> one change to the DB rippling out across the DB to other entries to keep
> them self-consistent.
>
> [Aside: Try to talk a self-updating database past change control some day.}

is exactly the sort of non-trivial thing that doesn't fit on a single
sheet of paper I mentioned in my post.  Things like this are where MI
is a great idea.  (defclass person ...) examples not so much.

> Worked like a charm, tho, thanks to multiple inheritance and   two
> metaclasses built to follow the rules.
>
> kenny
>
> ps. If no one needs multiple inheritance, how come everyone else fakes
> it with "interfaces" or dispatching schemes (ST, IIRC). k

Uh, read what I wrote again?  I ended by suggesting he find one of
those cases where Java people reinvent MI manually.

PS - Have you tried marrying Cells to Allegro Cache?
From: Ken Tilton
Subject: Re: Multiple inheritance examples?
Date: 
Message-ID: <47b08bc5$0$7882$607ed4bc@cv.net>
Thomas F. Burdick wrote:
> On Feb 11, 11:21 am, Ken Tilton <···········@optonline.net> wrote:
> 
>>Thomas F. Burdick wrote:
>>
>>>On Feb 8, 10:13 am, Tayssir John Gabbour <············@googlemail.com>
>>>wrote:
>>
>>>>Hi!
>>
>>>>I'm helping a Java-influenced person learn CLOS concepts. Does anyone
>>>>have good examples of multiple inheritance? Ones which aren't too
>>>>abstract?
>>
>>>>The best ones I can think of come from the GUI world. Like a widget
>>>>inheriting from a bordered mixin. Or in LispWorks, you have:
>>
>>>>   option-pane's superclasses: choice, titled-object, simple-pane
>>
>>>>I use a UUID mixin all the time for unique object identity, as I push
>>>>objects through networks or whatever. But I think that's too abstract
>>>>for my discussion.
>>
>>>>I'm hard-pressed to think of good examples of people. That would be
>>>>really nice. Maybe the concept of "person" might be combined with some
>>>>security mixin?
>>
>>>I don't think you will come up with any easy, pithy examples that
>>>don't break is-a relationships and don't come off as looking like more
>>>trouble than they're worth.
>>
>>Nonsense!
> 
> 
> I have no idea if you're disagreeing with me, or are in violent
> agreement or what.  For what it's worth, this :
> 
> 
>>Hell, I did multiple inheritance with /metaclasses/, combining
>>Cells and AllegroStore metaclasses to create databases that were alive,
>>one change to the DB rippling out across the DB to other entries to keep
>>them self-consistent.
>>
>>[Aside: Try to talk a self-updating database past change control some day.}
> 
> 
> is exactly the sort of non-trivial thing that doesn't fit on a single
> sheet of paper I mentioned in my post.  Things like this are where MI
> is a great idea.  (defclass person ...) examples not so much.

Sorry, I perhaps badly tried to convey the ubiquity of MI by saying, 
hey, even at the metaclass level. I gather now your emphasis was on the 
difficulty of dashing off a compelling toy example mid-flame. Oh, sure. 
Toys rarely inherit from Compeller.

Anyway, I have wearied of CLOS and types, bring on the RDF! Or maybe 
prototypes, defmodel seems prototype-y to me, so much so I have even 
consider finding out what are prototypes.

> Uh, read what I wrote again?

Too much like work.

>  I ended by suggesting he find one of
> those cases where Java people reinvent MI manually.
> 
> PS - Have you tried marrying Cells to Allegro Cache?

AllegroGraph, for my ECLM chat, just as far as a proof of concept unless 
someone hires me to go nuts over it.

kenny

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius