Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose for using an empty interface that extends another in Java?

I just begin to maintain a Java MVC project which use Java Guice Framework.

In almost the entire code, first developers passed as parameter an empty model interface extending another interface.

Here's the first Interface:

public interface FooModel extends ModelInterface {

}

And the other interface:

 public interface ModelInterface {
        public void addListener(FooListener fooListener);
        void setFoo(boolean blop);
        boolean isFoo();
    }

That does not make any sense for me.

Is there a good reason/pattern use empty interface, in Java? Maybe for Guice?

like image 929
Pier-Alexandre Bouchard Avatar asked May 14 '12 20:05

Pier-Alexandre Bouchard


1 Answers

Here is a good motivation for "marker interfaces". They are especially useful in aspect-oriented programming where they give you a point to attach to (and I guess Guice is just such a framework).

like image 200
Volker Stolz Avatar answered Oct 16 '22 13:10

Volker Stolz