| Author |
Why to use interfaces insted of Abstract Classes in some places?
|
Pras Tiwari
Ranch Hand
Joined: Nov 07, 2005
Posts: 185
|
|
Hi ranchers, As i know Interfaces are same as abstract classes (if we include only abstract methods in abstract class). Then why there are two different things in java(interfeces n classes), though Abstract classes can do functions of interfeces? I mean to say why interface came in java, though there is abstract class for same purpose? Is it due to "MULTIPLE INHERITANCE" limitation of Classes? PLease reply... pras
|
********Deserve Before You Desire********
|
 |
Naveen K Garg
Ranch Hand
Joined: Nov 28, 2005
Posts: 105
|
|
Hi Prashant, Please refer to following article for a detail understanding on Interface Vs Abstract Class uses. Design Principles from Design Patterns The GOF authers Erich Gamma himself explains there thinking and concept behind "Program to Interface not to Implementation". I found this so far a best explaination for Interface and Abstract Class. Regards Naveen
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Prashant Tiwari: Is it due to "MULTIPLE INHERITANCE" limitation of Classes?
Yes, that is exactly the only reason for the existance of interfaces in Java.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Naveen K Garg: The GOF authers Erich Gamma himself explains there thinking and concept behind "Program to Interface not to Implementation". I found this so far a best explaination for Interface and Abstract Class.
Read it again - Erich explicitely says that "programming to the interface" can be done using abstract classes. In languages that support multiple class inheritance, purely abstract classes are indistinguishable from Java interfaces.
|
 |
Naveen K Garg
Ranch Hand
Joined: Nov 28, 2005
Posts: 105
|
|
Hi Ilja, I 100% agree with you. But based my experience with various people, I found that they offten compare the general Interface term with Java Interface and hence the comfusion arise. The link that I have give here does explain this difference. Regards Naveen
|
 |
 |
|
|
subject: Why to use interfaces insted of Abstract Classes in some places?
|
|
|