User Id :    Password :      New Member   Forgot Password  
Topic: When to use Interface over abstract class
Anamika singh
13 Aug 2011 at 06:26 AM
When to use Interface over abstract class?
Re: When to use Interface over abstract class
Gaurav
14 Aug 2011 at 07:10 AM

Interface provides method signature and not the body. It’s up to the developers to provide body for these methods once they implement it.

Abstract provides both methods with and without body. Adding new methods in abstract class in middle of development life cycle won't break existing sub classes unless these methods are declared as must override. If there is frequent addition of new methods properties and so on. one should use abstract.

Adding new methods to the interface will force users to go through each and
every sub class that implemented that interface and call these methods.
So it’s always preferred to use abstract over interface because of this limitation.
Whereas on the other hand interface can fill gap of multiple inheritance. One can
implement from more than one interface. Not same with Abstract. One can inherit from only one abstract class.
If you want to inherit from class that can provide reusable code then uses abstract class. For instance connecting to the database or base class for grid or tree view. If you implement your subclass from an interface then in each subclass you will have to write your own code to fill body of these methods.

Total Replies: 1
 
Featured Text Ad

Featured Ad