• 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

OO Best Practices - Properties

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a quick sanity check on the correct "OO" way to handle properties...

My properties model consists of class named PropertiesManager that contains a private static Properties object, and all of the methods for getting/setting properties are public static. This lets me easily get/put a property from anywhere in my application. Since there are no non-static member variables, I did not see a reason to actually instantiate a new PropertiesManager object whenever I wanted to get a property.

How did you (collective) handle obtaining properties values throughout your code and does my way seem acceptable?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've implemented this pretty much exactly the way you have. The only difference I can think of is that my equivalent of 'PropertyManager' is more generic - I've called it 'Config', and the public API comments make no reference to the Properties class. To my mind, the backing Properties instance is an implementation detail. My class has some other config-related methods that don't use the Properties instance.

A nice thing about this setup is that your getter/setters can parse the fields and convert them into different types. For instance, if you have a numeric property, your getter/setter for that field can convert to/from int. This approach can be extended as far as Lists.
 
reply
    Bookmark Topic Watch Topic
  • New Topic