my dog learned polymorphism
The moose likes Java in General and the fly likes Library needs access to differnet constants Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Library needs access to differnet constants" Watch "Library needs access to differnet constants" New topic
Author

Library needs access to differnet constants

kevin Kinnett
Greenhorn

Joined: May 03, 2005
Posts: 2
Hello,

I have found myself using the same code over and over in different programs I am writing. So I decided to create a library. This is the first time I am doing this so I have a question.

The individual classes in the library need to have a different configuration depending on what program is using it. For instance I have a Swing widget that uses a custom icon. Up to now I have been using a constant class in the library that the library refers back to, however I would like to put that constant class in each project I am working on and have the library look back to it.

Is there a good way to do this? I have found that reading from a file each time is inefficient, especially if it is something like a simple sting.

Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26138
    
  66

Kevin,
Welcome to JavaRanch!

You are actually on the right track with the file idea. You can cache the value the first time you read it by storing it in a static variable. That minimizes the performance hit because it only happens once.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It sounds like these values are not constant since they differ depending on which program is running. My suggestion would be to create a class with the "constants" for each program. That program then passes the values as parameters to the methods in the library. What do you think?

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Library needs access to differnet constants
 
Similar Threads
Cost of Change
Visualizing instances of objects and their relationship
Compile Time Constant
OO design question?
What is a compile time constant?