One thing is still not clear to me that why people are using interface for storing just constants only ..when the java 5 had come up with it's new functionality of Enums..
interface OlympicMedal {
static final String GOLD = "Gold";
static final String SILVER = "Silver";
static final String BRONZE = "Bronze";
}
and another class is now implementing it..
public class OlympicAthlete implements OlympicMedal {
public OlympicAthlete( int aId ){
//..elided
}
//..elided
public void winEvent( ){
//the athlete gets a gold medal
//note the reference is not qualified, as
//in OlympicMedal.GOLD
fMedal = GOLD;
}
// PRIVATE //
private String fMedal; //possibly null
}
As seen above the same thing could be easily establish by enums also , Please let me know if I have choice to store the constants as above which should I choose enums or interface..!
the enum would be like...
public enum OlympicMedal {
GOLD, SILVER, BRONZ
}
But please advise how the class will access this constants now..!!