dcsimg
abstract class and interface
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   devaki_perumal
Posted On:   Wednesday, March 20, 2002 09:49 PM

when will you go for abstract class and when you will go for interface.
I think interface can be used when u think design may change and new types can be incorporated.
abstract class can be used to stop insatntiation .Can u pls tell some other points

Re: abstract class and interface

Posted By:   ram_kuppu  
Posted On:   Thursday, March 28, 2002 01:31 PM

Interface:Only to define the contract
how the implementation should be called
but there is no idea about the implementation.It gives full freedom to the implementor and at the same time totally hides implementation details from the user(easy to use).

eg: javax.servlet.Servlet interface


Abstract class:Part of the implementation can be provided while defining the contract but it is incomplete.Somewhat like partially implemented interface ...half boiled.So instantiation is not possible
without full implementation by extending it.


eg: javax.servlet.http.HttpServlet




So go for Abstract class if you have something to provide which is common to all implementation otherwise interface.

Re: abstract class and interface

Posted By:   Anonymous  
Posted On:   Thursday, March 21, 2002 01:14 AM

Please search through the FAQs before submitting a question:

When should I use an interface instead of an abstract class?

plus, similar questions has been asked recently.


Regards

About | Sitemap | Contact