• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Interface V/S Abstract class  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Hope this helps.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!