Re: Inheritance and Polymorhpism (getting back to the point)

From: Graham Perkins (grahamPerk_at_hotmail.com)
Date: 11/26/03


Date: 26 Nov 2003 06:00:32 -0800

igouy@yahoo.com (Isaac Gouy) wrote in message news:<ce7ef1c8.0311241439.488a5749@posting.google.com>...
> grahamPerk@hotmail.com (Graham Perkins) wrote in message news:<9b3b5be3.0311240157.597a2b14@posting.google.com>...

> It seems that your meaning of inheritance does not distinguish between
> sharing an implementation and sharing an interface - it includes both
> meanings.

I cannot help the way "inheritance" has become widely accepted
and implemented. Just looking at a few, (eg Eiffel, C++, Smalltalk,
Java, Borland Pascal, C#) we can see several flavours of inheriting
both implementation and interface, separately or together.

> (It seems that if the interface is behaving exactly like a pure
> abstract class then you regard it as the same as a class

If you want to say that the Java class hierarchy defining type
conformance and allowing polymorphism is "inheritance" and the
interface hierarchy defining type conformance and allowing
polymorphism is something else, then go right ahead! Then we
will have nothing to disagree about.

> Does Java reflection meet your requirements?

It could do. Here's an example from my MVC framework:

  -- assume Product has setQty and getQty methods
  Product p = ...
  IntAdaptor qtyEdit = new IntAdaptor( "getQty", "setQty", p );
  
Now inside the guts of IntMapper, reflection is used to
call those named methods in p whenever the adaptor's set
and get methods are called:

  qtyEdit.setValue( 5 ); -- calls p.setQty(5)
  n = qtyEdit.getValue(); -- calls p.getQty()

The polymorphism comes in because I allow the target of the
adaptor to be switched:

  qtyEdit.setTarget( anotherProductInstance );

Now the adaptor's set/get calls will bind to the "getQty"
and "setQty" methods in the new target, which may be different
actual methods. The new target doesn't have to be a Product
or Product subclass, so long as it implements getQty and setQty.

However, I'm effectively coding up my own binding mechanism
using reflection (which is exactly what Smalltalk does). I
suspect that this is a rather uncommon way of using reflection,
and generally its use in Java is orthogonal to polymorphism.



Relevant Pages

  • Re: whats the point of an interface?
    ... You are correct: inheritance of an interface ... is considered to be a form of polymorphism. ... inheritance acts as "Subtyping polymorphism". ... programmer helping programmers. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Meyer(s) gets it wrong
    ... > And, just as importantly, different underlying behaviour. ... just don't see the OOP sense of polymorphism here) I just don't ... > opposed to the interface of something. ... inheritance is sometimes named "is-a". ...
    (comp.programming)
  • Re: whats the point of an interface?
    ... >> implementation of a single interface. ... > This is inheritance, not polymorphism. ... In object-oriented programming theory, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Inheritance and Polymorhpism (getting back to the point)
    ... >>inheritance, and I'll try to answer the question. ... example of parametric polymorphism and there is no inheritance involved ... In this context I agree with Cozianu that the interface inheritance is ... But if those classes are not related through subclassing, ...
    (comp.object)
  • Re: Inheritance and Polymorhpism (getting back to the point)
    ... >>inheritance, and I'll try to answer the question. ... distinction between working to a common interface and sharing ... IMO the 'coupling' argument has become less persuasive - sharing ...
    (comp.object)