I just read somewhere that having an interface with common project constants is bad practice and also known as the Constant Interface Anti-Pattern. If I understood this correctly, the reason provided was that once implemented, the class would expose these constants to the public.
Well, I don't understand the need for 'implementing' in the first place. Isn't it possible to just use these static constants directly? So why do I have to go through the trouble of import static
when I can do something like:
interface Constants {
public static final int FOO_1 = 1;
public static final int FOO_2 = 2;
}
public class Test {
public static void main(String[] args) {
System.out.println(Constants.FOO_2);
}
}
I would appreciate any guidance to help me understand this a bit more.