Loading ...

Interface Vs Abstract

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  architecture   » Interface Vs Abstract

Interface Vs Abstract

Posts under the topic: Interface Vs Abstract

Posted: 8/19/2010

Lurker 17  points  Lurker
  • Joined on: 8/13/2010
  • Posts: 3

I want to know why Inteface come in picture except multiple inheritance.

For example

public interface IABC
{
    void GetName();
}
public abstract class XYZ
{
    public abstract void GetName();
}

above senario both method are mendatory to implement/override. both look like same

then why they add Interface. except use of multiple inheritance?

 

Please share your thoughts....

 


Posted: 8/19/2010

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79

Posted: 8/19/2010

Lurker 17  points  Lurker
  • Joined on: 8/13/2010
  • Posts: 3

I have red that article.. but i did not find answer..

if we can achive same or better thing through abstract. why interface come in to the picture.. ? except multiple inhertiance.


Posted: 8/19/2010

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79

sanjayjgoswami said:

user="sanjay goswami"]if we can achive same or better thing through abstract. why interface come in to the picture.. ?

Looks like you did not read that article properly:

In .NET you can derive from multiple interfaces, but then with time you might have a lot of interfaces created just to accomodate the extra features you developed over time and this can cause maintenance as well as performance issues. Hence you need to spend good amount of time while re-factoring your exisitng code into interfaces to make sure you have captured each and every functionality possible in your interface.

so if you dont need to support multiple intheritance, simply go with abstract classes. It is pretty simple.


 


Posted: 8/19/2010

Lurker 17  points  Lurker
  • Joined on: 8/13/2010
  • Posts: 3

Thanx.

 

I am asking is any other reason to use Interface,(not about multiple Inhertiance)?

 

If no then you mean to say interface is only add for achive multiple Inhertiance, If interface is only for multiple inhertinace then what is the reason mutliple inhertinace functionality not achiveable with normal class or ther class?

 

 


Posted: 8/19/2010

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79
  Answered

sanjayjgoswami said:

user="sanjay goswami"]I am asking is any other reason to use Interface,(not about multiple Inhertiance)?

Interfaces guarantee that there is no default functionality in the "blue print" definition. If your program will never change in terms of basic functionalities offered, its best to use Interfaces so that your program can be easily extended.

But if you think your program will have new features added later, then you have to use abstract classes so that you can have some default functionalities. Note that is becomes difficult for 3rd party developers to change their code if you use abstract classes code for new fucntionalities. So it depends on when to use interfaces or abstract classes.


Posted: 9/16/2010

Lurker 80  points  Lurker
  • Joined on: 9/14/2010
  • Posts: 8

hi sanjay check this blog post may it help's you

http://aspdotnet-suresh.blogspot.com/2010/04/abstract-versus-interface.html


Page 1 of 1 (7 items)