• Post Reply Bookmark Topic Watch Topic
  • New Topic

When to use Interface and abstract class  RSS feed

 
irrfan jamadar
Greenhorn
Posts: 10
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone help me out. when to use interface and abstract class with an real life example.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have a FAQ entry : InterfaceVsAbstractClass
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Irrfan Jamadar!

For broad questions like this, you should SearchFirst.(⇐click) This question has been asked an answered many times already.

Good luck, and if you still have specific questions after reading what's already out there, be sure to post them.
 
irrfan jamadar
Greenhorn
Posts: 10
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U Lindqvist wrote:
irrfan jamadar wrote:can anyone help me out. when to use interface and abstract class with an real life example.


There's a simple rule of thumb - always use an interface.

Using interfaces is always correct OO design. No one can ever blame you for that. If they still do just say it's to avoid the brittle superclass problem. And if that's not enough say you prefer composition before inheritance of implementation.

After you've used Java for a year or so you'll understand and can start using abstract classes in select cases.



Thank you for your reply.But posted comments before this does not explain the real life situation.They are just theory part and I am looking for real life example.
 
Palak Mathur
Ranch Hand
Posts: 343
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
irrfan jamadar wrote:
U Lindqvist wrote:
irrfan jamadar wrote:can anyone help me out. when to use interface and abstract class with an real life example.


There's a simple rule of thumb - always use an interface.

Using interfaces is always correct OO design. No one can ever blame you for that. If they still do just say it's to avoid the brittle superclass problem. And if that's not enough say you prefer composition before inheritance of implementation.

After you've used Java for a year or so you'll understand and can start using abstract classes in select cases.



Thank you for your reply.But posted comments before this does not explain the real life situation.They are just theory part and I am looking for real life example.


I will recommend that you first understand the object oriented concepts and then post your questions.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U Lindqvist wrote:
irrfan jamadar wrote:can anyone help me out. when to use interface and abstract class with an real life example.


There's a simple rule of thumb - always use an interface.


That's not a useful rule. Interfaces and abstract classes each have their place.

Using interfaces is always correct OO design.


No, definitely not.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!