I'm not sure there's a "better" answer... I'd say I see the first approach used more often... In fact, I'm not sure I can think of an instance where I've seen the second approach *IF* we're talking about an interface specifically for storing constants... Obviously when your extending an interface the second approach is probably the norm (i.e., most of the time I doubt anyone writes MyInterface.YES in that WayTwo.myMethod() below).

My own preference would be for the first approach. I'm a fan of code that is as obvious in meaning as possible. The first approach tells me pretty clearly that I'm referencing a field of the MyInterface class, the only question I have to answer then is if it's a static field or if MyInterface is actually a poorly-named instance of something. In the second approach, I could be dealing with a local variable, a class member, or something inherited. The difference isn't severe I think, but the first seems just slightly more intuitive, and that's always a good thing to me.

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

Carl Smith wrote:
In Java, sometimes you would define an interface containg the constants:
public interface MyInterface {
public static final String YES = "yes";
}
To access the contants, there are two ways
public class WayOne {
public void myMethod(){
String yes = MyInterface.YES;
//...
}
}
public class WayTwo implements MyInterface {
public void myMethod(){
String yes = YES;
//...
}
}
I am asking which one is better? Or they are Ok and depend on the developer 's flavor?




signature
                
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'




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



Reply via email to