Re: what's the point of an interface?
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 27 May 2005 07:21:07 +0100
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
.
- Follow-Ups:
- Re: what's the point of an interface?
- From: Nick Malik [Microsoft]
- Re: what's the point of an interface?
- References:
- what's the point of an interface?
- From: John Salerno
- Re: what's the point of an interface?
- From: Jeff Louie
- Re: what's the point of an interface?
- From: Nick Malik [Microsoft]
- what's the point of an interface?
- Prev by Date: Re: Finding server with broadcast
- Next by Date: Testing that a sql server is running
- Previous by thread: Re: what's the point of an interface?
- Next by thread: Re: what's the point of an interface?
- Index(es):
Relevant Pages
|