[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Why I need Interface

Umeshnath

8/10/2008 9:33:00 PM

My query is why I need an Interface, since my abstract class does the same
functionality

Interface
No implementation of methods - ------- This can achieved by abstract class
No instance creation just inheriting ----- This can achieved by abstract class

I know using interface we can go multiple inheritance
I am looking in such way the in terms of OOPS in C# what is the significance

Also I know there are certain places (WWF, WCF) only interface allows as
contracts, those things are MS design part.
I am looking why I need interface, if Abstract class does every thing

Thanks & Regards
Umeshnath


1 Answer

Peter Duniho

8/11/2008 12:24:00 AM

0

On Sun, 10 Aug 2008 14:33:01 -0700, Umeshnath
<Umeshnath@discussions.microsoft.com> wrote:

> My query is why I need an Interface, since my abstract class does the
> same
> functionality
>
> [...]
> I know using interface we can go multiple inheritance
> I am looking in such way the in terms of OOPS in C# what is the
> significance

If you understand that in C# you can only inherit one base class, I don't
understand why you're asking the question.

An abstract class is useful for providing some default or fundamental
implementation. But it ties you to a specific base class, preventing you
from inheriting any other base class. If you have no implementation you
want to provide through inheritance, why lock yourself into it by using an
abstract class rather than an interface?

Another important reason to use an interface is that value types can't
inherit abstract classes (and you can't make an abstract value type). So
if you want for your interface to be able to be implemented by a value
type, it has to be an interface, not an abstract class.

Basically, interfaces are more flexible, giving you more options. If you
have no need for the extras that an abstract class provides, then an
interface is the way to go.

Pete