• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relationship

 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know thatInheritence has "is - a" relationship and aggregation has "has - a" relationship.Can some tell me wht kinda relationship does interface have.
Thanx in advance.
Anukampa
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface is is-a relationship. It is one way we can get multiple inheritance. the other is inner classes.
 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall:
Could u pls tell me how do we get multiple inheritence thru inner classes since i m new to inner classes.
Thanx In advance.
Anukampa
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from "Thinking in Java":
A question that cuts to the heart of inner classes is this: if I just need a reference to an interface, why don�t I just make the outer class implement that interface? The answer is �If that�s all you need, then that�s how you should do it.� So what is it that distinguishes an inner class implementing an interface from an outer class implementing the same interface? The answer is that you can�t always have the convenience of interfaces�sometimes you�re working with implementations. So the most compelling reason for inner classes is:

Each inner class can independently inherit from an implementation. Thus, the inner class is not limited by whether the outer class is already inheriting from an implementation.

Without the ability that inner classes provide to inherit�in effect�from more than one concrete or abstract class, some design and programming problems would be intractable. So one way to look at the inner class is as the completion of the solution of the multiple-inheritance problem. Interfaces solve part of the problem, but inner classes effectively allow �multiple implementation inheritance.� That is, inner classes effectively allow you to inherit from more than one non-interface.

 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Randall. I have got yr point.
Anukampa.
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't implementing an interface 'has a' relationship'
beacuse doing so we 'have' the methods defined by interface.
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can upcast from a class to the interface it implements so it is definately an is-a relationship.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic