This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.