This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Must subclasses implement interfaces that their super-classes implement?

 
Jed Cousin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I create sub-class 'bar' that extends class 'foo', and class foo implements interface 'baz', must sub-class bar also implement interface baz?
 
Jimmy Die
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



No.

Bar will extend the methods you implemented in foo (and the ones you did not provide implementations for if any). If you did not provide concrete implementations of the methods from baz in foo, then foo is abstract. If bar doesn't provide concrete implementations of these methods then bar will also be abstract.
 
Jed Cousin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so baz becomes an integral part of foo (or bar) once the interface's abstract methods are made concrete. Thus obviating the need for a subclass (bar) to implement a superclass' interface (baz), as it's already been 'Borg-ed' by the superclass (foo).

Thanks man!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic