Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

How does one tie multiple interfaces into a single one?

Thread view: 
larkmore@aol.com - 13 Feb 2007 15:17 GMT
Hello all.  I have several separate interfaces defined that I'd like
to then lump together into one big interface file.  The catch here is
that I don't want to change the individual interfaces.  Is this
possible, and if yes, what is the syntax?
an example:

//My interface files (each one in a separate .java file)
public interface FooInterface1 {
 public void Foo1();
}

public interface FooInterface2 {
 public void Foo2();
}

public interface FooInterface3 {
 public void Foo3();
}

//What I'd love...
public interface FooCombined ???? FooInterface1, FooInterface2,
FooInterface3 {
}

public class FooObject implements FooCombined {
 public void Foo1(){}
 public void Foo2(){}
 public void Foo3(){}
}

//What I am trying to avoid
public class FooObject implements FooInterface1, FooInterface2,
FooInterface3 {
 public void Foo1(){}
 public void Foo2(){}
 public void Foo3(){}
}

Thanks for taking a look.  :)
-Will
Oliver Wong - 13 Feb 2007 15:45 GMT
> Hello all.  I have several separate interfaces defined that I'd like
> to then lump together into one big interface file.  The catch here is
[quoted text clipped - 33 lines]
>  public void Foo3(){}
> }

pulibc interface FooCombined extends FooInterfac1, FooInterfac2,
FooInterfac3 {
}

   - Oliver
larkmore@aol.com - 13 Feb 2007 16:18 GMT
> pulibc interface FooCombined extends FooInterfac1, FooInterfac2,
> FooInterfac3 {
>
> }
>
>     - Oliver

Weird, I thought that you could only extend one thing.  I guess that
only applies to classes and not to interfaces since the compiler seems
happy.  Neat, thanks!
-Will
Oliver Wong - 13 Feb 2007 16:43 GMT
>> pulibc interface FooCombined extends FooInterfac1, FooInterfac2,
>> FooInterfac3 {
[quoted text clipped - 4 lines]
> only applies to classes and not to interfaces since the compiler seems
> happy.  Neat, thanks!

   Right. You can only extend one class, but you can extend and/or
implement as many interfaces as you want. The reason why you can only extend
one class is to avoid the diamond problem:
http://en.wikipedia.org/wiki/Diamond_problem

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.