Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract classes and Interfaces in Project

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
This is a interview question .

Please tell me whether it is good to use Interfaces or abstract classes in a project ??

Actually i don't see any usefulness in using a Abstarct class

 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi, I think its good to use Interfaces and Abstract classes in your program, as it will increase encapsulation and promote code reusability.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i know we need to use Interfaces as Data Access Layer , but still cant get where Abstract classes will be useful actually . any scenario ??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Base functionality.

Do you have access to Google or other search engine?!
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:
This is a interview question .

Actually i don't see any usefulness in using a Abstarct class


Hopefully, you didn't answer this as such during the interview !

Henry
 
Hiram Nascimento
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

The key usefulness of Interfaces and Abstract classes is Polymorphism.

Also, once Java doesn't support multiple inheritance, Interfaces resolves the "Diamond of Death" problem if you know how to use them.

They also provide advantages for your application's design.

Did I convince you?

regards,
Hiram
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did I convince you?


some what

The question is not about my class extending multiple classes at same time .

But i use interface to define a contact but when to go with Abstrat class actually ??
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:But i use interface to define a contact but when to go with Abstrat class actually ??
Google is your friend
 
Hiram Nascimento
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface is a fully abstract class that only defines a contract and has no implementation.

All interface methods are implicitly public abstract.

The abstract classes accept you to define a contract but also allow you to implement some methods (which are concrete).

So, if you have a fully abstract class you have an Interface, if you have a partial abstract class you can have an Abstract Class, but if you have fully concrete class you have a normal Class.

Hiram
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic