Java Reference
In-Depth Information
public void secureOrder(Firework_1 f /*, etc. */)
{
//...
if (f.classification == Classification_1.DISPLAY)
{
// issue warning
}
else
{
// proceed
}
}
You can make the Oozinoz code a little cleaner if you move the classification constants to an
interface and use the
Classification
class solely for type checking. (The name of the
Classification
class does not end with a version number, indicating that we won't
refactor this class any further.) If you move the constants to an interface, you have to relax the
visibility of the
Classification
constructor:
package com.oozinoz.fireworks;
public class Classification
{
protected Classification()
{
}
}
public interface ClassificationConstants
{
static final Classification CONSUMER
= new Classification();
static final Classification DISPLAY
= new Classification();
}
Figure 2.3 shows the new relationship between
ClassificationConstants
and
Classification
. In this arrangement, the
Classification
class has no purpose other
than to provide type checking for parameters of the
Classification
type. But the
ClassificationConstants
interface lets you make the
secureOrder
() code more
readable.
Figure 2.3. The
ClassificationConstants
interface defines the two classifications of
fireworks that U.S. federal law recognizes.