Forums Register Login

abstract

+Pie Number of slices to send: Send
when to use abstract or interface in an project
+Pie Number of slices to send: Send
When To Use Interfaces
An interface allows somebody to start from scratch to implement your interface or implement your interface in some other code whose original or primary purpose was quite different from your interface. To them, your interface is only incidental, something that have to add on to the their code to be able to use your package.

When To Use Abstract classes
An abstract class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation. The catch is, code using it must use your class as the base. That may be highly inconvenient if the other programmers wanting to use your package have already developed their own class hierarchy independently. In Java, a class can inherit from only one base class.

When to Use Both
You can offer the best of both worlds, an interface and an abstract class. Implementors can ignore your abstract class if they choose. The only drawback of doing that is calling methods via their interface name is slightly slower than calling them via their abstract class name.
+Pie Number of slices to send: Send
 

calling methods via their interface name is slightly slower than calling them via their abstract class name.



I would like to see some evidence for that assertion.

Bill
+Pie Number of slices to send: Send
linta sebastian, please take the time to post your questions in the apporpriate forum. This forum is for questions on JSP.

I have moved this post to a more appropriate location.
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 804 times.
Similar Threads
interface and abstract
when to use interface and when abstract class
use of abstact class and interface
abstract class vs interface ?
interface vs abstraction
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:19:32.