• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Sachin Jai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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)?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!