To summarize Joshua Bloch,

Once you use an interface for constants, you allow users of that
interface to implement the interface to access the constants. 
However, that a class uses a constant internally is an implementation
detail.  The combination of these two things means that an
implementation detail is exported into the classes API.  This is a
poor design choices because: (a) the implementation of the interface
is of no consequence to the users ot the class; (b) the implementation
might confuse the users of the class; (c) if a future release of the
class is modified so that it does not need the constants, it still
must implement the interface to insure binary compatibility; (d) if a
nonfinal class implements such an interface, all of its subclasses
will have there namespace polluted by the constants in the interface. 
That ought to hold you, Frank, until the snow is cleared?

Anyway, there are option: (1) use a class (AClass) instead of an
interface (just change "interface" to "class") which contains the same
constants (AClass.SOME_CONSTANT) and avoid lots of typing as follows:
private static final double PI = Math.PI; (2) if constants are tied to
a particular class, put them in there as with MIN_VALUE in Integer;
(3) if the constants are best viewed as enumerated types, export them
with a type-safe enum class (Maybe different with TIger)  such as:

public class Suit {
  private final String name;
  private Suit(String name) { this.name = name; }
  public String toString() { return name; }
  public static final Suit CLUBS = new Suit("clubs");
  public static final Suit DIAMONDS = new Suit("diamonds");
  public static final Suit HEARTS = new Suit("hearts");
  public static final Suit SPADES = new Suit("spades");
}

 That's about it.  Pennsylvania is so beautiful, Frank.  I cannot
imagine how nice it must be to be in the snow there.  Enjoy!


<snip>
public class WayOne {
   public void myMethod(){
          String yes = MyInterface.YES;
          //...
   }
}

public class WayTwo implements MyInterface {
   public void myMethod(){
          String yes = YES;
          //...
   }
}
</snip>

The FIRST way is preferable, because you don't tie down the type, but
the SECOND way is the only sensible way to do it if you use an
interface, because there is no other reason to use an interface. 
However, this is why, in the big picture, why using an interface is
itself a design mistake, as others have noted Joshua Bloch has so
succinctly and pointedly showed.

Jack


-- 
------------------------------

"You can lead a horse to water but you cannot make it float on its back."

~Dakota Jack~

"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

-----------------------------------------------

"This message may contain confidential and/or privileged information.
If you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose, or take any action based
on this message or any information herein. If you have received this
message in error, please advise the sender immediately by reply e-mail
and delete this message. Thank you for your cooperation."

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to