aspose file tools*
The moose likes Java in General and the fly likes How to relate two interface ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to relate two interface ???" Watch "How to relate two interface ???" New topic
Author

How to relate two interface ???

Sachin Junghare
Greenhorn

Joined: Aug 19, 2003
Posts: 18
How can make relationship between two interface
interface I1 {}
interface I2 {}
without using extending the one with other.
Thanks in adavnce.
Sachin
Idly Vada
Ranch Hand

Joined: Sep 02, 2003
Posts: 135
I think extending is the only way
Is any one aware of other ways to do this???
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi Sachin
What kind of relationship you are looking for your interfaces? Either it can be "contains" or "extends" that are possible relations here I guess...
Also, whenever we have a relationship we have to have some explicit representation so without doing anything we can just logically know how they are related but can't expect computer to do that for us, right?
Regards
Maulin
Sachin Junghare
Greenhorn

Joined: Aug 19, 2003
Posts: 18
The question I am trying to ask without extends interfaces means how we contains Interface one members into interface two ....
I just know one way by extending ...but the question is asked me in the interview ....
so i put it here.
Sachin.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
How can make relationship between two interface
interface I1 {}
interface I2 {}
without using extending the one with other.

If you define interface I3, and both I1 and I2 extend I3, then both I1 and I2 will be of type I3 and therefore related.
Mathews P Srampikal
Ranch Hand

Joined: Nov 26, 2002
Posts: 211
Is it Possible to do this way..
inteface I1{}
inteface I2{}
class C implements I1,I2{
C(){
}
public static void main(String s[]){
I1=new C();
I2=new C();
}
}


Thanks,
Mathews
Sachin Junghare
Greenhorn

Joined: Aug 19, 2003
Posts: 18
it may be the possible way we can have relationship between interfaces
[code]
interface I1 {}
interface I2 {
class myclass implements I1{}
}
public class A {
public static void main(String arg[]) {
}
}
[code]
right!
Sachin.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi Sachin
I tried the following,

Here as you notice it doesn't enforce us to implement testI2 in testInterface1 even if "interface testI1 contains testI2". Also, we could extend testI2 seperately via testInterface2 class. So, here it seems that "contains" for interface would only be there for logical grouping because we can't just extend testI2 directly. We have to write testI1.testI2 you know...So essentially "contains" is used for "name space"....
Also, in the example that you give the same argument probably applies as the class inside the interface doesn't really make great sense to me...
Regards
Maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
I looked more into my arguments about "contains" relationship b/w interfaces and I found this group discussion
Please refer to the "Oreilly's Nutshell" quote there which says,
"
Nested interfaces are implicitly static ([snip]) and so are always
top level. A nested top-level class or interface behaves just like
a "normal" class or interface that is a member of a package. [snip]
Nested top-level classes and interfaces are typically used as a
convenient way to group related classes.
"
Regards
Maulin
Sachin Junghare
Greenhorn

Joined: Aug 19, 2003
Posts: 18
Thanks a lot Guys !
Sachin.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to relate two interface ???