Constant interface
Appearance
![]() | This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
No issues specified. Please specify issues, or remove this template. |
In the Java programming language, the constant interface anti-pattern describes the use of interfaces to define constants. This would enable classes implementing interface to use the constants as member variables. However, since the usage of constants is considered an implementation detail, it is considered inappropriate to define an interface for this purpose.[1]
Example
public interface Constants {
public static final double PI = 3.14159;
public static final double PLANCK_CONSTANT = 6.62606896e-34;
}
public class Calculations implements Constants {
public double getReducedPlanckConstant() {
return PLANCK_CONSTANT / (2 * PI);
}
}
Alternatives
References
- ^ Bloch, Joshua, Effective Java, 2nd Edition, p. 98