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.
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.