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