H
Hemal Pandya
Tony Morris said:Hemal Pandya said:Tony Morris said:I usually declare my 'public static final's to as String rather then
int for a somewhat safe usage, as a compromise in absence of enums. I
would appreciate any comments you may have on this scheme.
Comment: poor form.
Investigate the Type-safe enumeration design pattern.
Which type-safe enumeration design patterns are you referrning to? I
know of only one with some choices in implementation (one object per
element or one type per element). [....]
What makes you think I don't know about it? I was talking about a
lightweight alternative; type-safe enumeration, the way it is
usually described is too much code for too little syntactic sugar.
The way it is described is additional code and a slight performance hit for
more robust and maintainable software.
I (almost) always sacrifice performance for maintainability - it costs less
for a hardware upgrade than maintaining poorly written software.
Perhaps you did know about it?
I knew about it. I was asking about others; since your suggestion
implies (no assumption needed) that there is more then one pattern
that provides type safe enumeration.
Your suggestion implied (with asumption of ourse) the contrary.
Well, I happen to know about it, perhaps you assume too much? But as I
said earlier, too little syntactic sugar for too much code, at least
for my taste. Working in the real world, I find the Strings a good
compromise.
Yes, the check is at compile time in stead of runtime. But it does not
have the false positive of an int.