DEV Community

Discussion on: The Java Constants Interface Anti-Pattern

Collapse
 
darshitpp profile image
Darshit Patel

My suggestion is to keep the constants as close to their usage as possible

Yes, of course, that is true, and in such cases the usage is typically local or within the class itself. In these cases, it makes perfect sense to define constants using public static final within the classes they're being used. I, however, have encountered lots of usages of constants which are being shared across classes, and that is the point I was referring to.

Of course, constant interface shouldn't be implemented, and if someone really does that, one should have a quiet word with them in private :P