Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IS-A relationship for interfaces

 
Thomas Hauck
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The concept of "IS-A" is clear for a
subclass that inherits from a parent class.

I read that the same terminology holds true
for a class that implements an interface.

Proposition: When you implement an interface you get a "IS-A relationship"
between a reference type of the interface and the class that implements the interface.


Example 1:



The instanceof operator says that m1 of type 'Maintainable' is a 'House'
because the value of the variable state is true.

Example 2:


A "IS-A" X.

Please verify.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct. The "IS-A" relationship is basically inheritance. It doesn't matter the inherited object is a class or interface, as long as the inherited object's declaration has the "extends" or "implements" keyword. More examples:

Given
interface A {}
class X {}

interface B extends A {} // B is a A
class X implements B {} // X is a B and X is also a A
class Y extends X {} // Y is a X and Y is a B hence Y is a A
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IS-A is for inheritance and HAS-A is for composition. It does not matter if you inherit from an interface or an abstract class or a normal class. Inheritance is always IS-A relationship!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic