Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.
If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change.
Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality
to unrelated classes.
If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.
Interfaces and abstract classes have so much in common it's hard to make a desision at times.
Though you are already aware of the differences between interface and abstract classes, here is a quick summary regardomg definiton and differences of the following two just for general benefit.
Interface:
contains method definitions but does not contain any code nor any variables.
Abstracr Class: is a class that can not be instantiated but that can contain code. It
can contain internal member variables, and can contain basic behaviour in the form of methods that have been coded.
The following link leads to a tutorial that discusses plainly how to distinguish the two types and how to use them.
Hopefully this helps!
Best of Luck!
With Kind Regards,
Marked as answer by Angie xu - MSFT on Jan 03, 2013 07:16 AM
interfaces is actually a contract --you have to implement full interfaces & not any part .
These are binding but they normally make malleable entities and can be used for a variety of purposes -- i.e., talking of the same interface , as they do not have any implementations
abstract classes contain abstract methods indeed but not all of them .
It's an old topic about the choice of Interfaces and Abstract Classes, The choice of whether to design your functionality as an interface or an abstract class can sometimes be a difficult one.
An abstract class is a class that cannot be instantiated, but must be inherited from. An abstract class may be fully implemented, but is more usually partially implemented or not implemented at all, thereby encapsulating common functionality for
inherited classes.
and I think recommendations for Abstract Classes vs. Interfaces could be a good guide for you
here.
Kind regards
Please mark the replies as answers if they help or unmark if not.
Feedback to us
sureshtalla
Member
11 Points
82 Posts
Interface and Abstract Class
Dec 25, 2012 03:49 PM|LINK
Hi,
I know the difference between Interface and Abstract Classses, But i want to know in whcich situation Interfaces and Abstract Classes are used.
can any one please explain with an example.
Thanks,
Vipindas
Contributor
5514 Points
810 Posts
Re: Interface and Abstract Class
Dec 25, 2012 04:12 PM|LINK
Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.
Refer this
http://msdn.microsoft.com/en-us/library/scsyfw1d(v=vs.71).aspx
http://www.ronaldwidha.net/2008/06/16/a-good-example-of-abstract-class-vs-interface/
http://geekswithblogs.net/mahesh/archive/2006/07/05/84120.aspx
april_123456
Participant
775 Points
246 Posts
Re: Interface and Abstract Class
Dec 27, 2012 11:28 AM|LINK
Hello Sureshtalla,
Interfaces and abstract classes have so much in common it's hard to make a desision at times.
Though you are already aware of the differences between interface and abstract classes, here is a quick summary regardomg definiton and differences of the following two just for general benefit.
Interface: contains method definitions but does not contain any code nor any variables.
Abstracr Class: is a class that can not be instantiated but that can contain code. It can contain internal member variables, and can contain basic behaviour in the form of methods that have been coded.
The following link leads to a tutorial that discusses plainly how to distinguish the two types and how to use them.
Hopefully this helps!
Best of Luck!
With Kind Regards,
amigo 1
Member
60 Points
199 Posts
Re: Interface and Abstract Class
Dec 29, 2012 06:07 AM|LINK
interfaces is actually a contract --you have to implement full interfaces & not any part .
These are binding but they normally make malleable entities and can be used for a variety of purposes -- i.e., talking of the same interface , as they do not have any implementations
abstract classes contain abstract methods indeed but not all of them .
Angie xu - M...
All-Star
18491 Points
1570 Posts
Microsoft
Re: Interface and Abstract Class
Jan 01, 2013 04:29 AM|LINK
Hi sureshtalla
It's an old topic about the choice of Interfaces and Abstract Classes, The choice of whether to design your functionality as an interface or an abstract class can sometimes be a difficult one.
An abstract class is a class that cannot be instantiated, but must be inherited from. An abstract class may be fully implemented, but is more usually partially implemented or not implemented at all, thereby encapsulating common functionality for inherited classes.
and I think recommendations for Abstract Classes vs. Interfaces could be a good guide for you here.
Kind regards
Feedback to us
Develop and promote your apps in Windows Store