If I have a simple marker interface (contains no methods) which contains constants used throughout my application, is there any difference between a class importing the interface and actually implementing the interface?
Interface:
public interface MyConstants {
String constant1 = "constant1";
String constant2 = "constant2";
}
Implementing:
public class MyClass implements MyConstants {
public MyClass(){
System.out.println(constant1);
}
}
Importing:
import common.constants.MyConstants
public class MyClass {
public MyClass(){
System.out.println(MyConstants.constant1);
}
}
Implement it would be an anti-pattern:
http://en.wikipedia.org/wiki/Constant_interface
And regarding marker interface you can check it here.