what's the better place to declare constants, in class or interfaces?

constants, java

Solution

The constant interface pattern may be bad practice, but putting a constant in an interface doesn't make it a constant interface. So, if your constant is relevant at the interface level (so relevant to all clients of that interface), go ahead and put the constant into the interface. Nothing wrong with that.

Problem

Always I'm thinking where to put the constants, in interfaces like: ``` public interface MyInterface { ... public static final String MY_CONST = "const"; ... } ``` Or in classes like: ``` public class MyClass implements MyInterface { ... public static final String MY_CONST = "const"; ... } ``` What's the better place to define constants?

Original source

Related problems