Java - interface extension
Is it correct to propagate an empty interface? I just need to have a method (EventPlayer) with a parameter (EventCLass myEvent), which can be one class and next time another class.
public interface EventClass {
// ... empty ...
}
public interface EventClassExt1 extends EventClass {
public void firstEvent();
public void secondEvent();
}
public interface EventClassExt2 extends EventClass {
public void thirdEvent(String text);
}
public EventPlayer(final EventCLass myEvent)
source to share
Yes, it is normal.
If an interface has no methods, it is usually called a marker interface ; Serializable
is one of many examples of such an interface from the JDK.
Also, you probably don't want "class" in your interface name. Simply the Event
best choice.
source to share
Is it correct to propagate a class that doesn't have another object?
I am assuming you mean an empty interface.
This is something that was used over and over in Java before they had annotations to sign this type of class (from Java 5).
What you are doing right is basically you mark the extended type of interfaces / classes EventClass
, but I would use annotation which is a new way to do it
http://tutorials.jenkov.com/java-reflection/annotations.html
source to share