good place to bundle application wide constants?

I'm looking for some advice on the best practice for bundling application scoped constants. I've seen such things as putting the constant definitions in an interface, which is then imported in each class that needs to reference those constants.

If anyone has any comments, or a better idea, please let me know.

[326 byte] By [chadmichaela] at [2007-11-27 5:52:59]
# 1
the approach looks fine.
Yogesh.Nandwanaa at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...
# 2

You're not planning on having a class implement this alledged interface, I hope. That's a classic anti-pattern. I'd stick them in a class, rather than an interface, otherwise someone will at some point be tempted to implement that interface simply in order to get those constants "for free", which is entirely not the point of an interface

georgemca at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...
# 3
agree with georgemc:D
quittea at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...
# 4
If you are using version 5 then you also have the option of static imports: http://java.sun.com/developer/JDCTechTips/2004/tt1005.html#1The article includes the good and the bad.
jbisha at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...
# 5

Well, I don't intend to implement the interface. I was always deterred from that method by just the pollution of the type declaration. However, I saw people still placing the constants into an interface, rather than a class, and importing that interface.

I wonder why people would use an interface, even though they aren't implementing it. Is there some reason that an interface would be more efficient than a class for such purposes?

chadmichaela at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...
# 6

> Well, I don't intend to implement the interface. I

> was always deterred from that method by just the

> pollution of the type declaration. However, I saw

> people still placing the constants into an interface,

> rather than a class, and importing that interface.

At a guess, that's to "prevent" people instantiating it. Not worth the effort, if you ask me

> I wonder why people would use an interface, even

> though they aren't implementing it. Is there some

> reason that an interface would be more efficient than

> a class for such purposes?

None whatsoever

georgemca at 2007-7-12 15:45:10 > top of Java-index,Java Essentials,Java Programming...