wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Interface Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Question" Watch "Interface Question" New topic
Author

Interface Question

Rob Levo
Ranch Hand

Joined: Oct 01, 2000
Posts: 167
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
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).


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
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:

http://www.javaworld.com/javaworld/javatips/jw-javatip122.html
That's why, for my purposes, I still use interfaces hahaha
Rob Levo
Ranch Hand

Joined: Oct 01, 2000
Posts: 167
Thanks all!!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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:

http://www.javaworld.com/javaworld/javatips/jw-javatip122.html
That's why, for my purposes, I still use interfaces hahaha

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface Question
 
Similar Threads
Access to constants
What's the best way to declare global constants?
Performance: Constants vs Hard-Coded Text
Implements Vs Extends on a constants file
use interface or class for declaring constants?