Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface and abstract classes

 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am confused between an Interface and an abstract class. I would cite an example:

I consider various shape objects esp. square, rectangle etc. and consider a common behavior area which I need to determine. Should I consider an Interface or an abstract class and why?
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes

Abstract classes are used only when there is a �is-a� type of relationship between the classes.
Interfaces can be implemented by classes that are not related to one another.

You cannot extend more than one abstract class.
You can implement more than one interface.

Abstract class can implemented some methods also.
Interfaces can not implement methods.

With abstract classes, you are grabbing away each class�s individuality.
With Interfaces, you are merely extending each class�s functionality.
 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing out the differences but I am still inn confusion as to the choice between an interface or an abstract class in the above scenario. Could you please let me know what would be appropriate in the above scenario.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also try to read this FAQ.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic