Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Question about Inheritance


Message #1 by "dave" <dougwood@a...> on Sat, 10 Aug 2002 07:04:38
I'm reading Wrox (Beginning ASP.NET with C#)and wondering if someone could 
clear something up for me. In Chapter 9, in the 'Advanced Inheritance 
Concepts' section, the book mentions these definitions:

'Interfaces'- '....they can contain properties and methods, though methods 
can only be abstract methods, and as such any class that derives from the 
interface must implement them all'.

It goes on to say that "....a class can derive from zero or more 
interfaces, so long as each and every method defined by the interface is 
implemented."

What I don't understand is what they mean by "implemented" in this context.
what do they mean that the classes have to implement them. Does it mean 
that I HAVE to use each method of the interface??

can anyone come up with a short 'example' that can clarify this, or maybe 
just explain this concept better to me.

I would appreciate any help.
Thanks!!
Message #2 by Imar Spaanjaars <Imar@S...> on Sat, 10 Aug 2002 13:44:34 +0200
Hi Dave,

An interface doesn't define or contain any real implementations / code. 
It's only a contract of the properties, methods etc that classes that 
implement the interface should provide. You are not forced to "use" the 
methods, but you should provide an implementation for the required methods 
and properties of the interface in your class.

So, for example, if an interface defines a method:

         doIt()

the class that implements this interface is required to provide code (the 
implementation) for this method.

To successfully implement a certain interface, you must provide code for 
all required elements from the interface.

To read about this in some more detail, check out:

http://www.devx.com/codemag/articles/2002/mayjune/interfacebasedprogramming/codemag-1.asp

HtH

Imar



At 07:04 AM 8/10/2002 +0000, you wrote:
>I'm reading Wrox (Beginning ASP.NET with C#)and wondering if someone could
>clear something up for me. In Chapter 9, in the 'Advanced Inheritance
>Concepts' section, the book mentions these definitions:
>
>'Interfaces'- '....they can contain properties and methods, though methods
>can only be abstract methods, and as such any class that derives from the
>interface must implement them all'.
>
>It goes on to say that "....a class can derive from zero or more
>interfaces, so long as each and every method defined by the interface is
>implemented."
>
>What I don't understand is what they mean by "implemented" in this context.
>what do they mean that the classes have to implement them. Does it mean
>that I HAVE to use each method of the interface??
>
>can anyone come up with a short 'example' that can clarify this, or maybe
>just explain this concept better to me.
>
>I would appreciate any help.
>Thanks!!

Message #3 by "dave" <dougwood@a...> on Sat, 10 Aug 2002 19:37:59

Thanks Imar!, your explanation and the link you provided helped me a lot!
I have a much better grasp on Interfaces now.. thanks

  Return to Index