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

Breach in Interface Contract

 
Greenhorn
Posts: 19
Oracle Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I have this code where ChildClass implements an interface Demo . the same method signature is used in SuperClass.
This code compiles fine.
Isn't it the breach in the contract of implementing an interface?
even though ChildClass 'has'  doNothing() method but it doesn't implement it for the sake of Interface Contract.
what exactly is happening here.
 
Saloon Keeper
Posts: 7324
170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what the breach is supposed to be. ChildClass fulfills the interface that it is supposed to fulfill. That the method is inherited doesn’t matter.
 
Saloon Keeper
Posts: 13869
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't matter. To implement an interface, a class needs to 'have' all instance methods declared by the interface, with matching signatures and compatible return types and visibility. How it got them is of no consequence.
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its not a breach,actually here extending a superclass fulfills the
implementation of the interface simultaneously,that's how it renders the java standout of the multiple inheritance.
 
lowercase baba
Posts: 13048
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "contract" means that you can call the methods defined in the interface - not that each class has to explicitly implement them. You can quite clearly call doNothing on an instance of ChildClass, so the contract is fulfilled.
 
addy sharma
Greenhorn
Posts: 19
Oracle Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well thats correct.
The implementing class should "have" all the methods declared in an interface . its not written any where that it should 'implement' all the methods.
Comparator interface is an example  of the same.
Thanks for the clarification  
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this 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