I have a bunch of constants that need to be used by many classes. Does it make sense to create an interface with these constants even though the interface would have no methods. I understand an interface is supposed to act as a template for some behavior, this use would be a bit more limited. If classes need to share global variables, and an interface is not the way to go, what is typically done? Thanks.
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Take a look at this related conversation in the intermediate forum. And you may want to consider that object behavior is at times preferred over state-based solutions (not to mention a lot more interesting to explore and think about).
Originally posted by David Duran: If you read through that other thread and are thinking about type safe enumerations, I think it's very important to read the following article:
It's certainly important to notice this problems. But you should also notice that a) the serialization problem has a very simple solution (also presented in the article), and b) the classloader problem should be rather rare So, in my not so humble opinion, you shouldn't miss this powerfull pattern just because you fear that it might not be appropriate sometime in the future. YMMV
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus