• 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

Which is Better approach for defining resource bundle object as member or static

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing business logic for a web application in which web tier is done using JSF. My business logic is pretty much independent of UI aspects.

In few of my logic classes an error message bundle object is defined as:
/** The error message bundle object */
private static final AppResourceBundleUtil ERROR_MSG_RESOURCE_BUNDLE
= new AppResourceBundleUtil ( AppLogicConstants.APP_ERRORS );

Where AppResourceBundleUtil's construtor loads the resource bundle and this class has a method to access a message by key name.
My understanding is if I code this way then there will be many instances of AppResourceBundleUtil since they are static.

My confusion is should I define this object as public static final AppResourceBundleUtil ERROR_MSG_RESOURCE_BUNDLE in one utility class so that single instance is used in all the classes.
OR
Should I define as non static member in every class where I intend to use it : private final AppResourceBundleUtil ERROR_MSG_RESOURCE_BUNDLE

Which would be better approach?

TIA,
Sachin
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what you're after is that there's only one instantiation of the resource bundle that you can access across your application, is that correct? In that case having a singleton util class that loads the resource bundle once only and provides a method to access it is one potential solution (I'm sure others will weigh in here as well).
 
Sachin Jai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, you are correct, Singelton is one solution. But another doubt is what if I defined it as non static? Would that be inefficient ( from memory perspective)?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic