• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Library needs access to differnet constants

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic