• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set database file's name into a singleton Data class.

 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
My Data class is a singleton, there is a private constructor with one parameter and getInstance() method as following code:



In Sun's instructions, a user can put a database file's name via a GUI. When my application gets the database name, how can I push it into Data class, because my constructor can not be invoked direcly.

Thank you.
Surasak Lee
 
S Perreault
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An idea would be to always read the properties from the suncertify.properties file for your Data class to find the database.

UI updates the properties file and then the data class is constructed from the properties file.

I don't know if this will help you but it's an idea =)

Perogi.
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anyone help me.

Surasak Lee
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Surasak,

Perogi gave a good solution. Instead of just asking for more help, perhaps you could say what you see as being wrong with the solution given?

Alternative: have a setter method which sets the database name. Any attempts to get the instance of your Data class before the name is set will fail (with a suitable exception).

Another alternative: have the filename passed in as a parameter of the get instance method. That will have the added benefit of making it easy to change your Data class to a Multiton (instead of a Singleton) later.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic