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.
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
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?
> 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