Re: what's the point of an interface?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Nick Malik [Microsoft] <nickmalik@xxxxxxxxxxxxxxxxxx> wrote:
> minor nit
>
> > The third use of an interface is when you want to use the power of
> > polymorphism. In this technique, multiple classes all provide an
> > implementation of a single interface. You can then store instances of
> > these many different classes and simply call the interface method.
>
> This is inheritance, not polymorphism.

I disagree - it's inheritance of interface rather than inheritance of
implementation which is often understood by just the term
"inheritance", and it fits in well with all the definitions of
polymorphism I've seen. For instance:

<quote>
In computer science, polymorphism is the idea of allowing the same code
to be used with different classes of data (which classes in typed
languages correspond to types), resulting in more general and abstract
implementations.
</quote>

and

<quote>
In object-oriented programming theory, polymorphism is the ability of
objects belonging to different types to respond to methods of the same
name, each one according to the right type-specific behavior. The
programmer (and the program) does not have to know the exact type of
the object in advance, so this behavior can be implemented at run time
(this is called late binding or dynamic binding).
</quote>

That sounds like what Jeff was describing to me - admittedly without
the detail of "You can then store instances of these many different
classes [knowing only that they implement the interface] and simply
call the interface method."

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: A taxonomy of types
    ... (I do not see why inheritance is required here.) ... without an »object-oriented programming language«, for example, ... in the programming language used. ... indirectly) implements an interface IA whose declaration ...
    (comp.lang.misc)
  • Re: Inheritance and Polymorhpism (getting back to the point)
    ... > sharing an implementation and sharing an interface - it includes both ... I cannot help the way "inheritance" has become widely accepted ... both implementation and interface, separately or together. ... conformance and allowing polymorphism is "inheritance" and the ...
    (comp.object)
  • 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: Programming to an Interface
    ... found a reason why from programming to interfaces is better than ... You seem to be looking for two benefits of programming to an interface: ... Polymorphism. ... Improved likelihood of not impacting clients' code. ...
    (comp.object)
  • Re: Where are the other parigrams?
    ... >> programming to have code reuse or ... >> portability and changing of implementation vs interface (Unix in general, ... >> is always done in programming an extra layer (SDL or DirectX vs using ... Having polymorphism in code is ...
    (comp.programming)