![]() |
In the Java programming language, the constant interface pattern describes the use of an interface solely to define constants, and having classes implement that interface in order to achieve convenient syntactic access to those constants. However, since constants are very often merely an implementation detail, and the interfaces implemented by a class are part of its exported API, this practice amounts to putting implementations details into the API, which was considered inappropriate by, e.g., Java designer Joshua Bloch.[1] In general, collecting system constants into classes independent of behaviour might create a poor object-oriented design because it is often a sign of low cohesion. For these reasons, constant interfaces may be considered an anti-pattern.
Use of this pattern has a few other downsides:[original research?]
Note that the Java libraries use constant interface pattern themselves. For example, the SwingConstants interface[2] was released in 1998,[3] and then it was a reasonable choice.
© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search