How does one tie multiple interfaces into a single one?

L

larkmore

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
 
O

Oliver Wong

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(){}
}

pulibc interface FooCombined extends FooInterfac1, FooInterfac2,
FooInterfac3 {
}

- Oliver
 
L

larkmore

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
 
O

Oliver Wong

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!

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top