Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

why Interfaces in Java

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is difference between the following?



and



My exact question is what was the reason behind introduction of concept of interfaces even though they are not functional(why not classes as shown above which are at least functional)?Everywhere it is written that interfaces are part of contract but can't same be realized via classes as show above.Moreover client is interested in documentation stuff only.He is not interested in interfaces or other similar stuff?
Then why these interfaces(and also abstract classes)?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has been asked many, many, many times before. Please SearchFirst(←click).

And welcome to the Ranch!
 
Gautam Bhalla
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Already searched everywhere,But not getting a convincing answer?
 
lowercase baba
Posts: 13050
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gautam Bhalla wrote:Already searched everywhere,But not getting a convincing answer?


So what did you find, and what was not 'convincing' about it?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please allow me to try to answer this question.

Gautam mentioned functional, yes, but only interface(abstract class) has the function of a contract which requres the implementors to obey the rules and limitations set by the interface.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

drac yang wrote:only interface(abstract class) has the function of a contract which requres the implementors to obey the rules and limitations set by the interface.



That's not true. If you inherit from a public class, you are also required to keep to its contract, just as if you inherit from an abstract class or an interface.

Furthermore, none of this answers the OP's question. (Which is fine--he should search first and come back with what he found and what specifically he didn't understand about it.)
 
drac yang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:

drac yang wrote:only interface(abstract class) has the function of a contract which requres the implementors to obey the rules and limitations set by the interface.



That's not true. If you inherit from a public class, you are also required to keep to its contract, just as if you inherit from an abstract class or an interface.

Furthermore, none of this answers the OP's question. (Which is fine--he should search first and come back with what he found and what specifically he didn't understand about it.)



yes, you are right, thanks for pointing out. i didn't think of that.

since it is, the difference between interface and class is that besides one class could implement multiple interfaces which "extends" not, and interface was born not requiring implemenation, although you can leave blank for methods of class on purpose mimicking interface, interface focused on abstract essentials of all its implementors.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic