Jump to content

Constant interface

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Libsoc (talk | contribs) at 10:26, 8 March 2009 (Created page with 'In the Java programming language, the constant interface anti-pattern describes the use of interfaces to define constants. This wou…'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In the Java programming language, the constant interface anti-pattern describes the use of interfaces to define constants. This would enable implementors of the interface to use the constants as member variables. However, it is considered inappropriate to define an interface for other purposes than defining methods.[1]

Example

public interface Constants {

	static final double PI = 3.14159;

	static final double PLANCK_CONSTANT = 6.62606896e-34;

}


public class Calculations implements Constants {

	public double getReducedPlanckConstant() {
		return PLANCK_CONSTANT / (2 * PI);
	}

}

Alternatives

References

  1. ^ Bloch, Joshua, Effective Java, 2nd Edition, p. 98