## Shared Superclass Instances

From: "andrew cooke" <andrew@...>

Date: Fri, 24 Nov 2006 09:43:24 -0300 (CLST)

Imagine a language in which several sub-class instances can share single
super-class instances.

Classes are typically implemented as a chained list: at the head of the
list is the information associated with the "actual" (most specific)
class; next in the list is the information associated with the immediate
superclass; etc.

What happens if that list is a tree?

Inheritance seems to merge into association.  You could have a car where
all four wheels inherited from the same car.  Or from the appropriate
axle, which itself was a subclass of car.

Obviously that makes no sense from an "is-a" perspective.  But perhaps
"is-a" is a restriction imposed by the rigid way inheritance is
implemented in common OO languages these days.

As far as I know, what I describe is possible in prototype languages (Self
being the big example - maybe you can persuade JavaScript to do this too).

Personally, it doesn't seem like that great an idea to me.  Inheritance in
its restricted form is hard enough.  The reason why I mention this is that
at work we have a database schema that maps to objects with one table per
"extra" class (so tables are "chained" to reflect the inheritance tree of
a "full" class).  And through miscommunication I think we may have arrived
at a situation something like I describe above.  When I understood this
last night me immediate reaction was that we had done something
"illogical"; on reflection I think it's simply inconsistent with the way
we assume inheritance works.

Note that this is distinct from multiple inheritance, which is a relation
between classes; here I am talking about the relationship between ("sub"
or "partial") instances.

Andrew