Placing Constants in Interfaces

Interfaces and classes can also cooperate when it comes to defining constants. A constant is a field that is static and final.

Consider the definition of the classification of fireworks. In the United States, federal law defines two primary classifications, with each type of firework classified as either a consumer or a display type of firework. A display firework, any type of firework that is not a consumer firework, may be used only by licensed operators. In federal law, the consumer classification defines fireworks that states may allow ordinary citizens to purchase and to use. The consumer class is surprisingly large at the federal level, including rockets and aerial shells. State laws specify which consumer ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.