Hi, I have a design dilemma about the usage of interface vs abstract class. I have a set of classes which will have almost similar functionality and method signatures. Some methods in these classes are generic and hence can be implemented in a super class whereas others are very specific to the subclass. 1. Is it appropriate to just use an abstract class as superclass and then let other classes extend from it. Or 2. should I first write an interface defining the methods and put an abstract class that implements some of the methods from this interface and leave rest of the method implementation to the subclasses. Please let me know the relative pros and cons of the 2 approaches and which is more appropriate given the circumstances
In my opinion, it is better to create an interface, then an abstract class implementing the interface, and then the individual classes that extend the abstract class. This will give you the benifit of flexibility & extensibility in your application.
If in the future, you need to add another abstract class providing a seperate implementation set, it will be easier to implement within your eisting framework. It will also provide the added flexibility of having classes that can provide their own implementations of interface methods if they do not need to extend the abstract class.
Directly using abstract classes will also serve your purpose. You just need to evaluate how much flexibility do you need, and then decide on using either abstract classes or interfaces.