Saturday, August 23, 2014

EJ-19 Use Interfaces only to define types

Ref: Effective Java by Joshua Bloch

In this item, Mr Bloch mention about same symptom I have faced previously and shared in this post.

The constant interface pattern is a poor use of interfaces:

Instead use a utility class

If you make heavy use of the constants exported by a utility class, you can avoid the need for qualifying the constants with the class name by making use of the static import facility

In summary, interfaces should be used only to define types, they should not be used to export constants.

No comments: