Difference between abstract class and interface
6 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   janarthanan_kesavan
Posted On:   Sunday, September 28, 2003 11:29 PM

If you are provided an option of using abstract classes and interfaces,which one should you go for?What is the exact difference between an interface and an abstract class.

Re: Difference between abstract class and interface

Posted By:   Sachin_Gandhe  
Posted On:   Friday, October 10, 2003 06:17 AM

From so many replies, the difference betn Interface and abstract class might be clear. One more advantage i see in
using the interface is the great flexibility. If u are providing an interface for any product and leave the implementation on different vendors then it will be feasible for everybody. For e.g. ODBC drivers etc.

To put it simply, if u have designed some database then u will definitely be providing the apis which will access it.
But it's won't be feasible for u to provide the api's which
will be used by any language or tool which will be coming in future and using ur database product. But if u provide an interface then any other product using ur database product will give it's own api definition implementing the interfact provided by u. This will keep the user who is coding from the intricasies of the deployment.

But in true sense it's really the business need which decides the use of abstract class or interface.


cheers,

sachin.

Re: Difference between abstract class and interface

Posted By:   Sachin_Gandhe  
Posted On:   Friday, October 10, 2003 06:17 AM

From so many replies, the difference betn Interface and abstract class might be clear. One more advantage i see in
using the interface is the great flexibility. If u are providing an interface for any product and leave the implementation on different vendors then it will be feasible for everybody. For e.g. ODBC drivers etc.

To put it simply, if u have designed some database then u will definitely be providing the apis which will access it.
But it's won't be feasible for u to provide the api's which
will be used by any language or tool which will be coming in future and using ur database product. But if u provide an interface then any other product using ur database product will give it's own api definition implementing the interfact provided by u. This will keep the user who is coding from the intricasies of the deployment.

But in true sense it's really the business need which decides the use of abstract class or interface.


cheers,

sachin.

Re: Difference between abstract class and interface

Posted By:   Velayoudam_Kuberan  
Posted On:   Monday, October 6, 2003 11:00 PM

It depends on what your requirements are and in what context are you planning to use.
There is no thumb rule for this question.
You should know the advantages and the limitation of each approach, weigh them against your requirement, give considerations to future enhancements that you may have, and then follow the abstract class approach or interface approach or both.


For instance,
if you are developing a tool or a component that you would want someone to use, then I would choose both the interface and the abstract class approach.
typically the strategy followed by java swing classes.
It has an interface, an abstract class implementing that interface and a default class extending the abstract class.
The users of this component has got 3 options to choose from based on his requirement.


interface approach gives you flexibility, since you are the one who will be providing the implementation. but at the same you need to be worried about the implementation details.
abstract class gives you simplicity, since you are going to inherit the implementation.


This question is very much debatable, and can be answered convincingly only if there are specific requirements.

Re: Difference between abstract class and interface

Posted By:   Benoit_Quintin  
Posted On:   Monday, September 29, 2003 11:10 AM

RTFM

Re: Difference between abstract class and interface

Posted By:   hiubert_rajan  
Posted On:   Monday, September 29, 2003 10:30 AM

interface contain static data + abstract methods
in interface the method should be a public modifier
interface cannot be used for object construction
--------
abstract class may have concerte methods
it also cannot be instantiated;
----------
use:
when we have the situation that to develop a common application ..we keep an interface where there will be
only method declartion ...the person who wants it can
implement the interface and use his own logic by overridding the method...where in interface we have only all method declartion..

whereas in abstact class there willl be concerte methods
and some method declaration..the person who wants it can
extend the class and use the concrete methods +redefien
the methods..if he wish

Re: Difference between abstract class and interface

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, September 29, 2003 06:37 AM

Yes, I use both together, frequently.

About | Sitemap | Contact