Newsgroups: comp.lang.smalltalk,comp.object
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!gatech!swrinde!howland.reston.ans.net!math.ohio-state.edu!newsfeed.acns.nwu.edu!ftpbox!mothost!schbbs!news
From: shang@corp.mot.com (David L. Shang)
Subject: Re: Polymorphism One More Time
Reply-To: shang@corp.mot.com
Organization: MOTOROLA 
Date: Thu, 14 Mar 1996 16:27:23 GMT
Message-ID: <1996Mar14.162723.5586@schbbs.mot.com>
References: <4i6up0$cj7@news4.digex.net>
Sender: news@schbbs.mot.com (SCHBBS News Account)
Nntp-Posting-Host: 129.188.128.126
Lines: 53
Xref: glinda.oz.cs.cmu.edu comp.lang.smalltalk:35998 comp.object:45886

In article <4i6up0$cj7@news4.digex.net> ell@access2.digex.net (Ell) writes:
> John DiCamillo (milod@netcom.com) wrote: 
> "Paul G. Schaaf, Jr." <paul.schaaf@amd.com> writes: 
> :>MY DEFINITION (as posted earlier in this
> :>thread): Given a system of interacting objects, polymorphism is the
> :>ability to replace some object in that system with any other object
> :>provided that the new object implements the same interface as its
> :>predecessor.  By "implements the same interface", I mean the subset of
> :>that object's full interface that is excercised when the object is in that
> :>system.  A fully polymorphic system is one for which this is true for
> :>every object in that system. 
>  
> : This sounds more like the Liskov Substitutability Principle than
> : a definition of polymorphism.  
> 
> LSP should be a key part of any explanation of polymorphism, as I see it. 

Paul's definition is not precise. Substitutability cannot define
polymorphism.

Therefore two kinds of substitution: converted substitution and "no-loss"
substitution. By a converted substitution, "x" substitued with "y" should
reads: "x" substitued with "z" which is converted from "y", where "x" and
"z" has the same type. By a no-loss substitution, no conversion is allowed.
"y" should retains its original type.

To define that a "system" is polymorphic, we must first define what is
a system!

I am not trying to be ambitious. Instead, I am going to facus on a concrete
concept.

A variable is polymorphic if the variable can be attached to objects of
different types. Note that if a variable only support converted  attachment,
it is not polymorphic, but a polymorphic variable can use converted attachment
if it does not share object (e.g. a by-value varaible) with other variables.

So, the polymorphism itself has nothing to do with subtype. But a safe
polymorphism do require subtype rules and convertible type rules.

A non-polymorphic variable can use convertion to get a converted result
fron objects of different types.

The general rule is:

Polymorphic names by reference (e.g, Java, Eiffel's non-primitive variables,
and C++ pointers) should use subtype rules; and other names (sealed or by-
value variables) use convertible type rules (e.g. C++ variables, note that
C++ non-pointer varaibles are not polymorphic!)

David Shang


